forked from OSchip/llvm-project
[InstCombine] safely create a constant of the right type (PR35794)
llvm-svn: 321801
This commit is contained in:
parent
7d9198b296
commit
c63f9014d6
|
@ -4082,13 +4082,13 @@ Instruction *InstCombiner::foldICmpUsingKnownBits(ICmpInst &I) {
|
|||
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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue