[PATCH] D33984: [ScalarEvolution] Apply Depth limit to getMulExpr

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 9 14:48:07 PDT 2017


sanjoy requested changes to this revision.
sanjoy added inline comments.
This revision now requires changes to proceed.


================
Comment at: lib/Analysis/ScalarEvolution.cpp:2697
 
-  // If there are any constants, fold them together.
-  unsigned Idx = 0;
-  if (const SCEVConstant *LHSC = dyn_cast<SCEVConstant>(Ops[0])) {
-
-    // C1*(C2+V) -> C1*C2 + C1*V
-    if (Ops.size() == 2)
-        if (const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(Ops[1]))
-          // If any of Add's ops are Adds or Muls with a constant,
-          // apply this transformation as well.
-          if (Add->getNumOperands() == 2)
-            if (containsConstantSomewhere(Add))
-              return getAddExpr(getMulExpr(LHSC, Add->getOperand(0)),
-                                getMulExpr(LHSC, Add->getOperand(1)));
+  if (Depth <= MaxArithDepth) {
+    // If there are any constants, fold them together.
----------------
Why not do the same thing here as you did in `getAddExpr`:

```
  // Limit recursion calls depth
  if (Depth > MaxArithDepth)
    return getOrCreateMulExpr(Ops, Flags);
```



https://reviews.llvm.org/D33984





More information about the llvm-commits mailing list