[llvm] abbd684 - [InstCombine] Avoid ConstantExpr::get() in phi binop fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 4 07:46:52 PDT 2022
Author: Nikita Popov
Date: 2022-07-04T16:46:27+02:00
New Revision: abbd684c02c777aa8cdf992cc3a73e3ca356518b
URL: https://github.com/llvm/llvm-project/commit/abbd684c02c777aa8cdf992cc3a73e3ca356518b
DIFF: https://github.com/llvm/llvm-project/commit/abbd684c02c777aa8cdf992cc3a73e3ca356518b.diff
LOG: [InstCombine] Avoid ConstantExpr::get() in phi binop fold
Use ConstantFoldBinaryOpOperands() instead, in preparation for not
all binops having a supported constant expression.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 0816a4a575d9c..03358150d733e 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1324,6 +1324,11 @@ Instruction *InstCombinerImpl::foldBinopWithPhiOperands(BinaryOperator &BO) {
if (!isGuaranteedToTransferExecutionToSuccessor(&*BBIter))
return nullptr;
+ // Fold constants for the predecessor block with constant incoming values.
+ Constant *NewC = ConstantFoldBinaryOpOperands(BO.getOpcode(), C0, C1, DL);
+ if (!NewC)
+ return nullptr;
+
// Make a new binop in the predecessor block with the non-constant incoming
// values.
Builder.SetInsertPoint(PredBlockBranch);
@@ -1333,9 +1338,6 @@ Instruction *InstCombinerImpl::foldBinopWithPhiOperands(BinaryOperator &BO) {
if (auto *NotFoldedNewBO = dyn_cast<BinaryOperator>(NewBO))
NotFoldedNewBO->copyIRFlags(&BO);
- // Fold constants for the predecessor block with constant incoming values.
- Constant *NewC = ConstantExpr::get(BO.getOpcode(), C0, C1);
-
// Replace the binop with a phi of the new values. The old phis are dead.
PHINode *NewPhi = PHINode::Create(BO.getType(), 2);
NewPhi->addIncoming(NewBO, OtherBB);
More information about the llvm-commits
mailing list