[PATCH] D143129: [GVN] Restrict equality propagation for pointers

Usman Nadeem via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 27 11:29:29 PST 2023


mnadeem added inline comments.


================
Comment at: llvm/lib/Analysis/Loads.cpp:699
+  if (isa<PHINode>(U) && all_of(U->users(), [&](const User *User) {
+        return isa<PHINode>(User) ||
+               canReplacePointersRecursive(U, To, User, MaxLookup - 1);
----------------
aqjune wrote:
> Could you elaborate a bit about `isa<PHINode>(User)` condition?
> I think that in the following case replacing %p with %q should fail, but this condition seems to allow it:
> ```
> BB1:
>   %phi1 = phi [%p, <pred>], ..
>   br BB2
> BB2:
>   %phi2 = phi [%phi1, <BB1>], ..
>   store i32 0, ptr %phi2
> 
> ```
I was trying to handle something like the example below. I guess I didn't think about the cases where the second phi's use could have illegal replacements.

Not sure what the best way to handle this would be.

```
BB1:
  %phi1 = phi [%p, <pred>], ..
  %cond = icmp eq ptr %phi1 , %q    <<---- This case
  br BB2
BB2:
  %phi2 = phi [%phi1, <BB1>], ..
  store i32 0, ptr %phi2
```


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

https://reviews.llvm.org/D143129



More information about the llvm-commits mailing list