[llvm] 632594f - [InstCombine] Avoid ConstantExpr::get()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 20 06:24:10 PDT 2023


Author: Nikita Popov
Date: 2023-07-20T15:24:02+02:00
New Revision: 632594fcb1c9b6a25da32a58cd7364ce02aec745

URL: https://github.com/llvm/llvm-project/commit/632594fcb1c9b6a25da32a58cd7364ce02aec745
DIFF: https://github.com/llvm/llvm-project/commit/632594fcb1c9b6a25da32a58cd7364ce02aec745.diff

LOG: [InstCombine] Avoid ConstantExpr::get()

Use ConstantFoldBinaryOpOperands() instead of ConstantExpr::get().
This will continue working with binary operands that are not
supported as constant expressions.

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 4e731390533fe3..3fdd9195ed86cb 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -360,7 +360,11 @@ static bool simplifyAssocCastAssoc(BinaryOperator *BinOp1,
   // (op (cast (op X, C2)), C1) --> (op (cast X), FoldedC)
   Type *DestTy = C1->getType();
   Constant *CastC2 = ConstantExpr::getCast(CastOpcode, C2, DestTy);
-  Constant *FoldedC = ConstantExpr::get(AssocOpcode, C1, CastC2);
+  Constant *FoldedC =
+      ConstantFoldBinaryOpOperands(AssocOpcode, C1, CastC2, IC.getDataLayout());
+  if (!FoldedC)
+    return false;
+
   IC.replaceOperand(*Cast, 0, BinOp2->getOperand(0));
   IC.replaceOperand(*BinOp1, 1, FoldedC);
   return true;


        


More information about the llvm-commits mailing list