[PATCH] D144492: [InstCombine] Support multiple comparisons in foldAllocaCmp()

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 30 03:28:37 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:938
+        auto Res = ICmps.insert({ICmp, 0});
+        Res.first->second |= 1u << U->getOperandNo();
         return false;
----------------
goldstein.w.n wrote:
> Why does something like:
> ```
> target datalayout = "p:32:32"
> @gp = global ptr null, align 8
> declare ptr @hidden_inttoptr()
> declare void @witness(i1, i1)
> define void @src() {
>   %m = alloca i8, i32 4
>   %lgp = load ptr, ptr @gp, align 8
>   %rhs2 = call ptr @hidden_inttoptr()
>   %cmp1 = icmp eq ptr %m, %rhs2
>   %cmp2 = icmp eq ptr %lgp, %m
>   call void @witness(i1 %cmp1, i1 %cmp2)
>   ret void
> }
> ```
> 
> Work? Isn't `%m` on both sides? (Although it is fine to reduce this snippet), just dont understand what `U->getOperandNo()` is actually checking for.
What we care about is whether the alloca is on both sides of the same icmp. `icmp based_on(%alloca), %other` can be assumed to be false, `icmp %other, based_on(%alloca)` can be assumed to be false, but `icmp based_on(%alloca), based_on(%alloca)` may be true or false (but conversely, is not an escape, so we can ignore it entirely in this fold).


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

https://reviews.llvm.org/D144492



More information about the llvm-commits mailing list