aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-07-25 16:49:54 +0200
committerNikita Popov <npopov@redhat.com>2023-07-25 16:54:57 +0200
commit673a4671f3e8b7158d990f6456428175a6eac38c (patch)
tree4ff474c1852aa3bd8590be9763c94a6a5b81a372 /llvm/lib/IR/ConstantFold.cpp
parentb6cf0ea4e6d48a0b9d1fa9678825a27092c796b3 (diff)
downloadllvm-673a4671f3e8b7158d990f6456428175a6eac38c.zip
llvm-673a4671f3e8b7158d990f6456428175a6eac38c.tar.gz
llvm-673a4671f3e8b7158d990f6456428175a6eac38c.tar.bz2
[ConstantFold] Avoid creation of undesirable binop
When commuting the operands, don't create a constant expression for undesirable binops. Only invoke the constant folding function in that case.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 40b2187..04e4217 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1084,7 +1084,9 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
} else if (isa<ConstantInt>(C1)) {
// If C1 is a ConstantInt and C2 is not, swap the operands.
if (Instruction::isCommutative(Opcode))
- return ConstantExpr::get(Opcode, C2, C1);
+ return ConstantExpr::isDesirableBinOp(Opcode)
+ ? ConstantExpr::get(Opcode, C2, C1)
+ : ConstantFoldBinaryInstruction(Opcode, C2, C1);
}
if (ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {