diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-08-12 11:28:02 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-08-12 11:28:02 +0000 |
commit | ccdad6ef486a00ed815ead642d2f62d87d86ee90 (patch) | |
tree | aa68a38cfef0a52681ff57dbbd40a8d1b48622e0 /llvm | |
parent | 05e8209e3347f636e93af9182c913259ec2bbffa (diff) | |
download | bcm5719-llvm-ccdad6ef486a00ed815ead642d2f62d87d86ee90.tar.gz bcm5719-llvm-ccdad6ef486a00ed815ead642d2f62d87d86ee90.zip |
[InstCombine] foldShiftIntoShiftInAnotherHandOfAndInICmp(): avoid constantexpr pitfail (PR42962)
Instead of matching value and then blindly casting to BinaryOperator
just to get the opcode, just match instruction and do no cast.
Fixes https://bugs.llvm.org/show_bug.cgi?id=42962
llvm-svn: 368554
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 11 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest.ll | 12 |
2 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 46294ad732a..22e02969d6a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3312,10 +3312,10 @@ foldShiftIntoShiftInAnotherHandOfAndInICmp(ICmpInst &I, const SimplifyQuery SQ, // Look for an 'and' of two (opposite) logical shifts. // Pick the single-use shift as XShift. - Value *XShift, *YShift; + Instruction *XShift, *YShift; if (!match(I.getOperand(0), - m_c_And(m_CombineAnd(m_AnyLogicalShift, m_Value(XShift)), - m_CombineAnd(m_AnyLogicalShift, m_Value(YShift))))) + m_c_And(m_CombineAnd(m_AnyLogicalShift, m_Instruction(XShift)), + m_CombineAnd(m_AnyLogicalShift, m_Instruction(YShift))))) return nullptr; // If YShift is a 'lshr', swap the shifts around. @@ -3323,9 +3323,8 @@ foldShiftIntoShiftInAnotherHandOfAndInICmp(ICmpInst &I, const SimplifyQuery SQ, std::swap(XShift, YShift); // The shifts must be in opposite directions. - Instruction::BinaryOps XShiftOpcode = - cast<BinaryOperator>(XShift)->getOpcode(); - if (XShiftOpcode == cast<BinaryOperator>(YShift)->getOpcode()) + auto XShiftOpcode = XShift->getOpcode(); + if (XShiftOpcode == YShift->getOpcode()) return nullptr; // Do not care about same-direction shifts here. Value *X, *XShAmt, *Y, *YShAmt; diff --git a/llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest.ll b/llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest.ll index 55d268b9b77..9a2cfa5977a 100644 --- a/llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest.ll +++ b/llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest.ll @@ -667,3 +667,15 @@ define <2 x i1> @n38_overshift(<2 x i32> %x, <2 x i32> %y) { %t3 = icmp ne <2 x i32> %t2, <i32 0, i32 0> ret <2 x i1> %t3 } + +; As usual, don't crash given constantexpr's :/ +@f.a = internal global i16 0 +define i1 @constantexpr() { +entry: + %0 = load i16, i16* @f.a + %shr = ashr i16 %0, 1 + %shr1 = ashr i16 %shr, zext (i1 icmp ne (i16 ptrtoint (i16* @f.a to i16), i16 1) to i16) + %and = and i16 %shr1, 1 + %tobool = icmp ne i16 %and, 0 + ret i1 %tobool +} |