[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 00:23:04 PDT 2021
Allen created this revision.
Herald added a subscriber: hiraditya.
Allen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Some pass such as Loop Vectorization(-fvectorize) may generate undef elements
constant, which will ball out the combine optimization.
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,16 @@
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.364939.patch
Type: text/x-patch
Size: 1723 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210807/be7cbd9d/attachment.bin>
More information about the llvm-commits
mailing list