diff options
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/icmp.ll | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 262c86cb59f..12f716d5023 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1893,9 +1893,10 @@ Instruction *InstCombiner::foldICmpOrConstant(ICmpInst &Cmp, Instruction *Or, if (match(Or, m_Or(m_PtrToInt(m_Value(P)), m_PtrToInt(m_Value(Q))))) { // Simplify icmp eq (or (ptrtoint P), (ptrtoint Q)), 0 // -> and (icmp eq P, null), (icmp eq Q, null). - Constant *NullVal = ConstantInt::getNullValue(P->getType()); - Value *CmpP = Builder->CreateICmp(Pred, P, NullVal); - Value *CmpQ = Builder->CreateICmp(Pred, Q, NullVal); + Value *CmpP = + Builder->CreateICmp(Pred, P, ConstantInt::getNullValue(P->getType())); + Value *CmpQ = + Builder->CreateICmp(Pred, Q, ConstantInt::getNullValue(Q->getType())); auto LogicOpc = Pred == ICmpInst::Predicate::ICMP_EQ ? Instruction::And : Instruction::Or; return BinaryOperator::Create(LogicOpc, CmpP, CmpQ); diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index cfb29a98006..b15a960c0db 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -2605,3 +2605,16 @@ define <2 x i1> @ugtKnownBitsVec(<2 x i8> %a) { ret <2 x i1> %cmp } +define i1 @or_ptrtoint_mismatch(i8* %p, i32* %q) { +; CHECK-LABEL: define i1 @or_ptrtoint_mismatch(i8* %p, i32* %q) +; CHECK: [[pc:%.*]] = icmp eq i8* %p, null +; CHECK: [[qc:%.*]] = icmp eq i32* %q, null +; CHECK: [[b:%.*]] = and i1 [[pc]], [[qc]] +; CHECK: ret i1 [[b]] + + %pp = ptrtoint i8* %p to i64 + %qq = ptrtoint i32* %q to i64 + %o = or i64 %pp, %qq + %b = icmp eq i64 %o, 0 + ret i1 %b +} |

