[llvm] [InstCombine] Fold fneg over select (PR #89947)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 24 17:15:14 PDT 2024
================
@@ -2781,6 +2781,16 @@ Instruction *InstCombinerImpl::visitFNeg(UnaryOperator &I) {
propagateSelectFMF(NewSel, P == X);
return NewSel;
}
+
+ // -(Cond ? X : C) --> Cond ? -X : -C
+ // -(Cond ? C : Y) --> Cond ? -C : -Y
+ if (match(X, m_ImmConstant()) || match(Y, m_ImmConstant())) {
+ Value *NegX = Builder.CreateFNegFMF(X, &I, X->getName() + ".neg");
+ Value *NegY = Builder.CreateFNegFMF(Y, &I, Y->getName() + ".neg");
+ SelectInst *NewSel = SelectInst::Create(Cond, NegX, NegY);
+ propagateSelectFMF(NewSel, /*CommonOperand=*/true);
+ return NewSel;
+ }
----------------
nikic wrote:
Can we use FoldOpIntoSelect here instead?
https://github.com/llvm/llvm-project/pull/89947
More information about the llvm-commits
mailing list