Skip to content

Commit 632594f

Browse files
committed
[InstCombine] Avoid ConstantExpr::get()
Use ConstantFoldBinaryOpOperands() instead of ConstantExpr::get(). This will continue working with binary operands that are not supported as constant expressions.
1 parent 095e694 commit 632594f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,11 @@ static bool simplifyAssocCastAssoc(BinaryOperator *BinOp1,
360360
// (op (cast (op X, C2)), C1) --> (op (cast X), FoldedC)
361361
Type *DestTy = C1->getType();
362362
Constant *CastC2 = ConstantExpr::getCast(CastOpcode, C2, DestTy);
363-
Constant *FoldedC = ConstantExpr::get(AssocOpcode, C1, CastC2);
363+
Constant *FoldedC =
364+
ConstantFoldBinaryOpOperands(AssocOpcode, C1, CastC2, IC.getDataLayout());
365+
if (!FoldedC)
366+
return false;
367+
364368
IC.replaceOperand(*Cast, 0, BinOp2->getOperand(0));
365369
IC.replaceOperand(*BinOp1, 1, FoldedC);
366370
return true;

0 commit comments

Comments
 (0)