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

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 31 03:34:28 PDT 2018


mkazantsev 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.
----------------
etherzhhb wrote:
> 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?)
I guess constant values are always profitable to rewrite and don't need to pass through hard uses check. I'll take a look how exactly it's handled. It should not go on this check anyways.


https://reviews.llvm.org/D51584





More information about the llvm-commits mailing list