[PATCH] D51584: [IndVars] Smart hard uses detection

Hongbin Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 18 09:17:16 PDT 2018


etherzhhb added inline comments.


================
Comment at: lib/Transforms/Scalar/IndVarSimplify.cpp:557-558
+    // Do we assume it is a "hard" use which will not be eliminated easily?
+    if (Curr->mayHaveSideEffects())
+      return true;
+    // Otherwise, add all its users to worklist.
----------------
we may also stop and return true if Curr is a phi node, since phi nodes cannot be eliminated easily.

But we need to be careful that:

```
define void @test6(i32 %m, i32* %p) nounwind uwtable {
entry:
  br label %for.body

for.body:                                         ; preds = %for.body, %entry
  %i.06 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
  %a.05 = phi i32 [ 0, %entry ], [ %add, %for.body ]
  %inc = add nsw i32 %i.06, 1
  %exitcond = icmp eq i32 %inc, 186
  br i1 %exitcond, label %for.end, label %for.body

for.end:                                          ; preds = %for.body
  tail call void @func(i32 %inc)
  ret void
}
```

In this case we still what to rewrite %inc outside of the loop to a constant. (or it is handle by the other part of this pass?)


https://reviews.llvm.org/D51584





More information about the llvm-commits mailing list