[PATCH] D37888: [SCEV] Generalize folding of trunc(x)+n*trunc(y) into folding m*trunc(x)+n*trunc(y)

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 10:29:26 PDT 2017


sanjoy 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) {
----------------
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?


https://reviews.llvm.org/D37888





More information about the llvm-commits mailing list