Skip to content

Commit

Permalink
[InstCombine] Avoid ConstantExpr::get()
Browse files Browse the repository at this point in the history
Use ConstantFoldBinaryOpOperands() instead of ConstantExpr::get().
This will continue working with binary operands that are not
supported as constant expressions.
  • Loading branch information
nikic committed Jul 20, 2023
1 parent 095e694 commit 632594f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 632594f

Please sign in to comment.