[PATCH] D37888: [SCEV] Generalize folding of trunc(x)+n*trunc(y) into folding m*trunc(x)+n*trunc(y)
Daniel Neilson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 20 10:48:33 PDT 2017
dneilson added inline comments.
================
Comment at: lib/Analysis/ScalarEvolution.cpp:2351
+ if (const auto *Mul = dyn_cast<SCEVMulExpr>(Ops[i])) {
+ bool Ok = true;
+ for (unsigned j = 0, e = Mul->getNumOperands(); Ok && j < e; ++j) {
----------------
sanjoy wrote:
> I think we can rewrite this inner loop as:
>
> ```
> auto *LastOp = Mul->getOperand(Mul->getNumOperands() - 1);
> if (auto *T = dyn_cast<SCEVTruncateExpr>(LastOp))
> return T->getOperand()->getType();
> if (!isa<SCEVConstant>(LastOp))
> break;
> ```
>
> I think we can use this trick in the outer loop as well. If we just look at the last operand to the add then we'll miss (say) zero extend expressions etc. but that's fine because the loop that actually does the work will catch it. Here we just need to provide a quick "estimate".
>
> What do you think?
Sounds like a good idea to me. I wasn't aware that the operands of all SCEV expressions are sorted.
Should be able to apply this trick down below as well.
https://reviews.llvm.org/D37888
More information about the llvm-commits
mailing list