[llvm] [InstCombine] Use InstSimplify in FoldOpIntoSelect (PR #116073)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 13 16:43:06 PST 2024
================
@@ -1649,39 +1649,34 @@ Instruction *InstCombinerImpl::foldBinopOfSextBoolToSelect(BinaryOperator &BO) {
return SelectInst::Create(X, TVal, FVal);
}
-static Constant *constantFoldOperationIntoSelectOperand(Instruction &I,
- SelectInst *SI,
- bool IsTrueArm) {
- SmallVector<Constant *> ConstOps;
+static Value *simplifyOperationIntoSelectOperand(Instruction &I, SelectInst *SI,
+ bool IsTrueArm) {
+ SmallVector<Value *> Ops;
for (Value *Op : I.operands()) {
- Constant *C = nullptr;
+ Value *V = nullptr;
if (Op == SI) {
- C = dyn_cast<Constant>(IsTrueArm ? SI->getTrueValue()
- : SI->getFalseValue());
+ V = IsTrueArm ? SI->getTrueValue() : SI->getFalseValue();
} else if (match(SI->getCondition(),
m_SpecificICmp(IsTrueArm ? ICmpInst::ICMP_EQ
: ICmpInst::ICMP_NE,
- m_Specific(Op), m_Constant(C))) &&
- isGuaranteedNotToBeUndefOrPoison(C)) {
+ m_Specific(Op), m_Value(V))) &&
+ isGuaranteedNotToBeUndefOrPoison(V)) {
// Pass
} else {
- C = dyn_cast<Constant>(Op);
+ V = Op;
}
- if (C == nullptr)
- return nullptr;
-
- ConstOps.push_back(C);
+ Ops.push_back(V);
}
- return ConstantFoldInstOperands(&I, ConstOps, I.getDataLayout());
+ return simplifyInstructionWithOperands(&I, Ops, I.getDataLayout());
}
static Value *foldOperationIntoSelectOperand(Instruction &I, SelectInst *SI,
Value *NewOp, InstCombiner &IC) {
Instruction *Clone = I.clone();
Clone->replaceUsesOfWith(SI, NewOp);
Clone->dropUBImplyingAttrsAndMetadata();
- IC.InsertNewInstBefore(Clone, SI->getIterator());
+ IC.InsertNewInstBefore(Clone, I.getIterator());
----------------
dtcxzyw wrote:
Can you explain this change?
https://github.com/llvm/llvm-project/pull/116073
More information about the llvm-commits
mailing list