[llvm] [InstCombine] Fix vector icmp handling in alloc removal (PR #196031)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 02:22:59 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/196031

A vector icmp can occur after #195486.

>From d0c5a617559cd7aa22f4a4ca8b1653aa7b0f0f19 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 6 May 2026 11:19:22 +0200
Subject: [PATCH] [InstCombine] Fix vector icmp handling in alloc removal

A vector icmp can occur after #195486.
---
 llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 5 ++---
 llvm/test/Transforms/InstCombine/compare-unescaped.ll    | 9 +++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 489fe9f904a14..a09f881e06595 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3977,9 +3977,8 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
       Instruction *I = cast<Instruction>(&*User);
 
       if (ICmpInst *C = dyn_cast<ICmpInst>(I)) {
-        replaceInstUsesWith(*C,
-                            ConstantInt::get(Type::getInt1Ty(C->getContext()),
-                                             C->isFalseWhenEqual()));
+        replaceInstUsesWith(
+            *C, ConstantInt::get(C->getType(), C->isFalseWhenEqual()));
       } else if (auto *SI = dyn_cast<StoreInst>(I)) {
         for (auto *DVR : DVRs)
           if (DVR->isAddressOfVariable())
diff --git a/llvm/test/Transforms/InstCombine/compare-unescaped.ll b/llvm/test/Transforms/InstCombine/compare-unescaped.ll
index 31e3e4581a2ef..333358446c235 100644
--- a/llvm/test/Transforms/InstCombine/compare-unescaped.ll
+++ b/llvm/test/Transforms/InstCombine/compare-unescaped.ll
@@ -395,6 +395,15 @@ define i1 @two_nonnull_mallocs_hidden() {
   ret i1 %cmp
 }
 
+define <4 x i1> @test_vector_icmp() {
+; CHECK-LABEL: @test_vector_icmp(
+; CHECK-NEXT:    ret <4 x i1> zeroinitializer
+;
+  %ptr = call ptr @malloc(i64 16)
+  %gep = getelementptr i8, ptr %ptr, <4 x i64> <i64 4, i64 8, i64 12, i64 16>
+  %cmp = icmp eq <4 x ptr> %gep, splat (ptr null)
+  ret <4 x i1> %cmp
+}
 
 !0 = !{}
 



More information about the llvm-commits mailing list