Skip to content

Commit

Permalink
[JumpThreading] Avoid ConstantExpr::get() (NFCI)
Browse files Browse the repository at this point in the history
This code requires the result to be an UndefValue/ConstantInt
anyway (checked by getKnownConstant), so we are only interested
in the case where this folds.
  • Loading branch information
nikic committed Jun 29, 2022
1 parent 741f8f2 commit 2124b2f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Scalar/JumpThreading.cpp
Expand Up @@ -788,14 +788,16 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
if (Preference != WantInteger)
return false;
if (ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1))) {
const DataLayout &DL = BO->getModule()->getDataLayout();
PredValueInfoTy LHSVals;
computeValueKnownInPredecessorsImpl(BO->getOperand(0), BB, LHSVals,
WantInteger, RecursionSet, CxtI);

// Try to use constant folding to simplify the binary operator.
for (const auto &LHSVal : LHSVals) {
Constant *V = LHSVal.first;
Constant *Folded = ConstantExpr::get(BO->getOpcode(), V, CI);
Constant *Folded =
ConstantFoldBinaryOpOperands(BO->getOpcode(), V, CI, DL);

if (Constant *KC = getKnownConstant(Folded, WantInteger))
Result.emplace_back(KC, LHSVal.second);
Expand Down

0 comments on commit 2124b2f

Please sign in to comment.