[llvm] [InstCombine] Fix a cycle when folding fneg(select) with scalable vector types (PR #112465)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 23:44:33 PDT 2024
================
@@ -2878,13 +2878,22 @@ Instruction *InstCombinerImpl::visitFNeg(UnaryOperator &I) {
// -(Cond ? X : C) --> Cond ? -X : -C
// -(Cond ? C : Y) --> Cond ? -C : -Y
- if ((match(X, m_ImmConstant()) && !isa<ScalableVectorType>(X->getType())) ||
- (match(Y, m_ImmConstant()) && !isa<ScalableVectorType>(Y->getType()))) {
- 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;
+ Constant *XC = nullptr, *YC = nullptr;
+ if (match(X, m_ImmConstant(XC)) || match(Y, m_ImmConstant(YC))) {
+ Value *NegX = nullptr, *NegY = nullptr;
+ if (XC)
+ NegX = ConstantFoldUnaryOpOperand(Instruction::FNeg, XC, DL);
+ if (YC)
+ NegY = ConstantFoldUnaryOpOperand(Instruction::FNeg, YC, DL);
----------------
arsenm wrote:
Generally the attempt to constant fold should be hidden inside the IRBuilder Create* functions
https://github.com/llvm/llvm-project/pull/112465
More information about the llvm-commits
mailing list