[llvm] [InstSimplify] Stop propagating `undef` when element is demanded (PR #75746)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 17 10:27:45 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Antonio Frighetto (antoniofrighetto)
<details>
<summary>Changes</summary>
Do not poison `undef` demanded elements in `SimplifyDemandedVectorElts`. A miscompilation issue has been addressed with refined checking.
Proofs: https://alive2.llvm.org/ce/z/WA5oD5.
---
Full diff: https://github.com/llvm/llvm-project/pull/75746.diff
3 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (+1-1)
- (modified) llvm/test/Transforms/InstCombine/insert-const-shuf.ll (+1-1)
- (modified) llvm/test/Transforms/InstCombine/vec_shuffle.ll (+11)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 846116a929b156..4e314780c1f3db 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1378,7 +1378,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
if (!Elt) return nullptr;
Elts.push_back(Elt);
- if (isa<UndefValue>(Elt)) // Already undef or poison.
+ if (isa<PoisonValue>(Elt)) // Already poison.
UndefElts.setBit(i);
}
diff --git a/llvm/test/Transforms/InstCombine/insert-const-shuf.ll b/llvm/test/Transforms/InstCombine/insert-const-shuf.ll
index 68dcc45e4b6c36..1a6528d8855685 100644
--- a/llvm/test/Transforms/InstCombine/insert-const-shuf.ll
+++ b/llvm/test/Transforms/InstCombine/insert-const-shuf.ll
@@ -94,7 +94,7 @@ define <3 x float> @twoShufUses(<3 x float> %x) {
define <5 x i8> @longerMask(<3 x i8> %x) {
; CHECK-LABEL: @longerMask(
-; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x i8> [[X:%.*]], <3 x i8> <i8 poison, i8 1, i8 poison>, <5 x i32> <i32 2, i32 1, i32 4, i32 poison, i32 poison>
+; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x i8> [[X:%.*]], <3 x i8> <i8 undef, i8 1, i8 poison>, <5 x i32> <i32 2, i32 1, i32 4, i32 3, i32 poison>
; CHECK-NEXT: [[INS:%.*]] = insertelement <5 x i8> [[SHUF]], i8 42, i64 4
; CHECK-NEXT: ret <5 x i8> [[INS]]
;
diff --git a/llvm/test/Transforms/InstCombine/vec_shuffle.ll b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
index 0081da2c0aad75..978d90d7df94ed 100644
--- a/llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -2332,3 +2332,14 @@ define <2 x float> @uitofp_shuf_narrow(<4 x i32> %x, <4 x i32> %y) {
%r = shufflevector <4 x float> %nx, <4 x float> %ny, <2 x i32> <i32 3, i32 5>
ret <2 x float> %r
}
+
+define <4 x i16> @blend_elements_from_load(ptr align 8 %_0) {
+; CHECK-LABEL: @blend_elements_from_load(
+; CHECK-NEXT: [[LOAD:%.*]] = load <3 x i16>, ptr [[_0:%.*]], align 8
+; CHECK-NEXT: [[RV:%.*]] = shufflevector <3 x i16> <i16 0, i16 undef, i16 poison>, <3 x i16> [[LOAD]], <4 x i32> <i32 0, i32 1, i32 3, i32 5>
+; CHECK-NEXT: ret <4 x i16> [[RV]]
+;
+ %load = load <3 x i16>, ptr %_0, align 8
+ %rv = shufflevector <3 x i16> <i16 0, i16 undef, i16 undef>, <3 x i16> %load, <4 x i32> <i32 0, i32 1, i32 3, i32 5>
+ ret <4 x i16> %rv
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/75746
More information about the llvm-commits
mailing list