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-27 09:48:54 +0200
commit90d825be708cd09ab7bfbb6b7a10a98a9847c7c4 (patch)
treec55a8f44ece7c8bc549599d5c2be38236a4c105c /llvm/lib/IR/ConstantFold.cpp
parent47ba908a5e8ee94828b035184df315601803d60f (diff)
downloadllvm-90d825be708cd09ab7bfbb6b7a10a98a9847c7c4.zip
llvm-90d825be708cd09ab7bfbb6b7a10a98a9847c7c4.tar.gz
llvm-90d825be708cd09ab7bfbb6b7a10a98a9847c7c4.tar.bz2
Reapply [ConstantFold] Avoid creation of undesirable binop
This was reverted together with another commit due to a test conflict. Reapply without functional changes. ----- 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 4c33250..db1a83b 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)) {