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

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 02:53:55 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:959
+    }
+    case 3:
+      // Both icmp operands are based on the alloca, so this is comparing
----------------
goldstein.w.n wrote:
> You could add a todo here for some simplifications i.e
> ```
> define i1 @foo(i64 %x) {
>   %alloc = alloca i64, i64 8
>   %p = getelementptr i64, ptr %alloc, i64 %x
>   %q = getelementptr i64, ptr %alloc, i64 3
>   %cmp = icmp eq ptr %p, %q
>   ret i1 %cmp
> }
> ```
> 
> is really `icmp eq i64 %x, 3`.
I went ahead and implemented this in https://github.com/llvm/llvm-project/commit/e8ec42b80b5dc75186dca543572416f2f2e21475 and https://github.com/llvm/llvm-project/commit/289542b1e72dc4fe17093952dfb1b04cce259183.


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

https://reviews.llvm.org/D144492



More information about the llvm-commits mailing list