forked from OSchip/llvm-project
Fix bug in FoldFCmp_IntToFP_Cst. If inttofp is a uintofp, use unsigned instead of signed integer constant.
llvm-svn: 72300
This commit is contained in:
parent
36fe6901d4
commit
a838a40bc4
|
@ -5598,12 +5598,17 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
|
|||
// [0, UMAX], but it may still be fractional. See if it is fractional by
|
||||
// casting the FP value to the integer value and back, checking for equality.
|
||||
// Don't do this for zero, because -0.0 is not fractional.
|
||||
Constant *RHSInt = ConstantExpr::getFPToSI(RHSC, IntTy);
|
||||
if (!RHS.isZero() &&
|
||||
ConstantExpr::getSIToFP(RHSInt, RHSC->getType()) != RHSC) {
|
||||
// If we had a comparison against a fractional value, we have to adjust the
|
||||
// compare predicate and sometimes the value. RHSC is rounded towards zero
|
||||
// at this point.
|
||||
Constant *RHSInt = LHSUnsigned
|
||||
? ConstantExpr::getFPToUI(RHSC, IntTy)
|
||||
: ConstantExpr::getFPToSI(RHSC, IntTy);
|
||||
if (!RHS.isZero()) {
|
||||
bool Equal = LHSUnsigned
|
||||
? ConstantExpr::getUIToFP(RHSInt, RHSC->getType()) == RHSC
|
||||
: ConstantExpr::getSIToFP(RHSInt, RHSC->getType()) == RHSC;
|
||||
if (!Equal) {
|
||||
// If we had a comparison against a fractional value, we have to adjust
|
||||
// the compare predicate and sometimes the value. RHSC is rounded towards
|
||||
// zero at this point.
|
||||
switch (Pred) {
|
||||
default: assert(0 && "Unexpected integer comparison!");
|
||||
case ICmpInst::ICMP_NE: // (float)int != 4.4 --> true
|
||||
|
@ -5662,6 +5667,7 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lower this FP comparison into an appropriate integer version of the
|
||||
// comparison.
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep cmp
|
||||
; rdar://6903175
|
||||
|
||||
define i1 @f0(i32 *%a) nounwind {
|
||||
%b = load i32* %a, align 4
|
||||
%c = uitofp i32 %b to double
|
||||
%d = fcmp ogt double %c, 0x41EFFFFFFFE00000
|
||||
ret i1 %d
|
||||
}
|
Loading…
Reference in New Issue