[PATCH] D107691: [InstCombine] Prevent the transform of the comparison for all undef elements

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 7 03:17:35 PDT 2021


Allen updated this revision to Diff 364948.

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

https://reviews.llvm.org/D107691

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Transforms/InstCombine/icmp-bc-vec-inseltpoison.ll


Index: llvm/test/Transforms/InstCombine/icmp-bc-vec-inseltpoison.ll
===================================================================
--- llvm/test/Transforms/InstCombine/icmp-bc-vec-inseltpoison.ll
+++ llvm/test/Transforms/InstCombine/icmp-bc-vec-inseltpoison.ll
@@ -125,3 +125,14 @@
   %cmp = icmp slt i27 %cast, 262657 ; 0x040201
   ret i1 %cmp
 }
+
+; Verify the case that all elements are under define
+define <4 x i1> @test_i32_ule_pattern(i32 %val) {
+; CHECK-LABEL: @test_i32_ule_pattern(
+; CHECK-NEXT:    ret <4 x i1> <i1 true, i1 true, i1 true, i1 true>
+;
+  %insvec = insertelement <4 x i32> poison, i32 %val, i32 0
+  %vec = shufflevector <4 x i32> %insvec, <4 x i32> poison, <4 x i32> zeroinitializer
+  %cond = icmp ule <4 x i32> %vec, <i32 undef, i32 poison, i32 poison, i32 poison>
+  ret <4 x i1> %cond
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5274,12 +5274,15 @@
     return llvm::None;
   }
 
+  // May be all elements are under value
+  if (C->containsUndefOrPoisonElement() && SafeReplacementConstant == nullptr)
+    return llvm::None;
+
   // It may not be safe to change a compare predicate in the presence of
   // undefined elements, so replace those elements with the first safe constant
   // that we found.
   // TODO: in case of poison, it is safe; let's replace undefs only.
   if (C->containsUndefOrPoisonElement()) {
-    assert(SafeReplacementConstant && "Replacement constant not set");
     C = Constant::replaceUndefsWith(C, SafeReplacementConstant);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107691.364948.patch
Type: text/x-patch
Size: 1716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210807/210bb66b/attachment.bin>


More information about the llvm-commits mailing list