mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-13 11:30:21 +00:00
[InstCombine] propagate fast-math-flags when folding fcmp+fneg
This is another part of solving PR39475: https://bugs.llvm.org/show_bug.cgi?id=39475 This might be enough to fix that particular issue, but as noted with the FIXME, we're still dropping FMF on other folds around here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346234 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
07c5c7fbf9
commit
bd1a44f2b8
@ -5445,14 +5445,6 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
|
||||
if (Instruction *NV = foldFCmpIntToFPConst(I, LHSI, RHSC))
|
||||
return NV;
|
||||
break;
|
||||
case Instruction::FSub: {
|
||||
// fcmp pred (fneg x), C -> fcmp swap(pred) x, -C
|
||||
Value *Op;
|
||||
if (match(LHSI, m_FNeg(m_Value(Op))))
|
||||
return new FCmpInst(I.getSwappedPredicate(), Op,
|
||||
ConstantExpr::getFNeg(RHSC));
|
||||
break;
|
||||
}
|
||||
case Instruction::FDiv:
|
||||
if (Instruction *NV = foldFCmpReciprocalAndZero(I, LHSI, RHSC))
|
||||
return NV;
|
||||
@ -5472,10 +5464,23 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
|
||||
}
|
||||
}
|
||||
|
||||
// fcmp pred (fneg x), (fneg y) -> fcmp swap(pred) x, y
|
||||
Value *X, *Y;
|
||||
if (match(Op0, m_FNeg(m_Value(X))) && match(Op1, m_FNeg(m_Value(Y))))
|
||||
return new FCmpInst(I.getSwappedPredicate(), X, Y);
|
||||
if (match(Op0, m_FNeg(m_Value(X)))) {
|
||||
if (match(Op1, m_FNeg(m_Value(Y)))) {
|
||||
// FIXME: Drops FMF.
|
||||
// fcmp pred (fneg X), (fneg Y) -> fcmp swap(pred) X, Y
|
||||
return new FCmpInst(I.getSwappedPredicate(), X, Y);
|
||||
}
|
||||
|
||||
Constant *C;
|
||||
if (match(Op1, m_Constant(C))) {
|
||||
// fcmp pred (fneg X), C --> fcmp swap(pred) X, -C
|
||||
Constant *NegC = ConstantExpr::getFNeg(C);
|
||||
Instruction *NewFCmp = new FCmpInst(I.getSwappedPredicate(), X, NegC);
|
||||
NewFCmp->copyFastMathFlags(&I);
|
||||
return NewFCmp;
|
||||
}
|
||||
}
|
||||
|
||||
// fcmp (fpext x), (fpext y) -> fcmp x, y
|
||||
if (FPExtInst *LHSExt = dyn_cast<FPExtInst>(Op0))
|
||||
|
@ -82,7 +82,7 @@ define <2 x i1> @fneg_constant_swap_pred_vec_undef(<2 x float> %x) {
|
||||
|
||||
define i1 @fneg_fmf(float %x) {
|
||||
; CHECK-LABEL: @fneg_fmf(
|
||||
; CHECK-NEXT: [[R:%.*]] = fcmp oeq float [[X:%.*]], -4.200000e+01
|
||||
; CHECK-NEXT: [[R:%.*]] = fcmp fast oeq float [[X:%.*]], -4.200000e+01
|
||||
; CHECK-NEXT: ret i1 [[R]]
|
||||
;
|
||||
%n = fsub fast float -0.0, %x
|
||||
@ -94,7 +94,7 @@ define i1 @fneg_fmf(float %x) {
|
||||
|
||||
define <2 x i1> @fcmp_fneg_fmf_vec(<2 x float> %x) {
|
||||
; CHECK-LABEL: @fcmp_fneg_fmf_vec(
|
||||
; CHECK-NEXT: [[R:%.*]] = fcmp ule <2 x float> [[X:%.*]], <float -4.200000e+01, float 1.900000e+01>
|
||||
; CHECK-NEXT: [[R:%.*]] = fcmp reassoc nnan ule <2 x float> [[X:%.*]], <float -4.200000e+01, float 1.900000e+01>
|
||||
; CHECK-NEXT: ret <2 x i1> [[R]]
|
||||
;
|
||||
%n = fsub nsz <2 x float> zeroinitializer, %x
|
||||
|
Loading…
x
Reference in New Issue
Block a user