Skip to content

Commit f2e4e8b

Browse files
committed
Only the constant folding change is needed; revert the fneg folding change
1 parent e871975 commit f2e4e8b

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,22 +2878,12 @@ Instruction *InstCombinerImpl::visitFNeg(UnaryOperator &I) {
28782878

28792879
// -(Cond ? X : C) --> Cond ? -X : -C
28802880
// -(Cond ? C : Y) --> Cond ? -C : -Y
2881-
Constant *XC = nullptr, *YC = nullptr;
2882-
if (match(X, m_ImmConstant(XC)) || match(Y, m_ImmConstant(YC))) {
2883-
Value *NegX = nullptr, *NegY = nullptr;
2884-
if (XC)
2885-
NegX = ConstantFoldUnaryOpOperand(Instruction::FNeg, XC, DL);
2886-
if (YC)
2887-
NegY = ConstantFoldUnaryOpOperand(Instruction::FNeg, YC, DL);
2888-
if (NegX || NegY) {
2889-
if (!NegX)
2890-
NegX = Builder.CreateFNegFMF(X, &I, X->getName() + ".neg");
2891-
if (!NegY)
2892-
NegY = Builder.CreateFNegFMF(Y, &I, Y->getName() + ".neg");
2893-
SelectInst *NewSel = SelectInst::Create(Cond, NegX, NegY);
2894-
propagateSelectFMF(NewSel, /*CommonOperand=*/true);
2895-
return NewSel;
2896-
}
2881+
if (match(X, m_ImmConstant()) || match(Y, m_ImmConstant())) {
2882+
Value *NegX = Builder.CreateFNegFMF(X, &I, X->getName() + ".neg");
2883+
Value *NegY = Builder.CreateFNegFMF(Y, &I, Y->getName() + ".neg");
2884+
SelectInst *NewSel = SelectInst::Create(Cond, NegX, NegY);
2885+
propagateSelectFMF(NewSel, /*CommonOperand=*/true);
2886+
return NewSel;
28972887
}
28982888
}
28992889

0 commit comments

Comments
 (0)