[llvm] r321801 - [InstCombine] safely create a constant of the right type (PR35794)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 4 06:31:56 PST 2018
Author: spatel
Date: Thu Jan 4 06:31:56 2018
New Revision: 321801
URL: http://llvm.org/viewvc/llvm-project?rev=321801&view=rev
Log:
[InstCombine] safely create a constant of the right type (PR35794)
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=321801&r1=321800&r2=321801&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Jan 4 06:31:56 2018
@@ -4082,13 +4082,13 @@ Instruction *InstCombiner::foldICmpUsing
computeUnsignedMinMaxValuesFromKnownBits(Op1Known, Op1Min, Op1Max);
}
- // If Min and Max are known to be the same, then SimplifyDemandedBits
- // figured out that the LHS is a constant. Constant fold this now, so that
+ // If Min and Max are known to be the same, then SimplifyDemandedBits figured
+ // out that the LHS or RHS is a constant. Constant fold this now, so that
// code below can assume that Min != Max.
if (!isa<Constant>(Op0) && Op0Min == Op0Max)
- return new ICmpInst(Pred, ConstantInt::get(Op0->getType(), Op0Min), Op1);
+ return new ICmpInst(Pred, ConstantExpr::getIntegerValue(Ty, Op0Min), Op1);
if (!isa<Constant>(Op1) && Op1Min == Op1Max)
- return new ICmpInst(Pred, Op0, ConstantInt::get(Op1->getType(), Op1Min));
+ return new ICmpInst(Pred, Op0, ConstantExpr::getIntegerValue(Ty, Op1Min));
// Based on the range information we know about the LHS, see if we can
// simplify this comparison. For example, (x&4) < 8 is always true.
Modified: llvm/trunk/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp.ll?rev=321801&r1=321800&r2=321801&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp.ll Thu Jan 4 06:31:56 2018
@@ -3286,3 +3286,19 @@ define i32 @abs_preserve(i32 %x) {
%abs = select i1 %c, i32 %a, i32 %nega
ret i32 %abs
}
+
+; Don't crash by assuming the compared values are integers.
+
+declare void @llvm.assume(i1)
+define i1 @PR35794(i32* %a) {
+; CHECK-LABEL: @PR35794(
+; CHECK-NEXT: [[MASKCOND:%.*]] = icmp eq i32* %a, null
+; CHECK-NEXT: tail call void @llvm.assume(i1 [[MASKCOND]])
+; CHECK-NEXT: ret i1 true
+;
+ %cmp = icmp sgt i32* %a, inttoptr (i64 -1 to i32*)
+ %maskcond = icmp eq i32* %a, null
+ tail call void @llvm.assume(i1 %maskcond)
+ ret i1 %cmp
+}
+
More information about the llvm-commits
mailing list