[PATCH] D89550: [IndVars] Recognize 'sub nuw' expressed as 'add' for widening

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 2 11:31:26 PST 2020


fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1158
     for (Use &U : NarrowUse->uses()) {
+      if (U.getUser() == NarrowDef)
+        continue;
----------------
This seems independent of the `add x, -y` -> `sub nuw`? Can this be split off into a separate patch? IIUC the test case for the detection without this change would be something like

```
loop:
  %iv = phi i32 [%start, %entry], [%iv.next.1, %backedge]
  %cond = icmp eq i32 %iv, 0
  br i1 %cond, label %exit, label %backedge

backedge:
  %foo = add i32 %iv, -1
  %index = zext i32 %foo to i64
  %store.addr = getelementptr i32, i32* %p, i64 %index
  store i32 1, i32* %store.addr
  %load.addr = getelementptr i32, i32* %q, i64 %index
  %stop = load i32, i32* %q
  %loop.cond = icmp eq i32 %stop, 0
  %iv.next.1 = add i32 %iv, -1
  br i1 %loop.cond, label %loop, label %failure

```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89550/new/

https://reviews.llvm.org/D89550



More information about the llvm-commits mailing list