Author: Kieran B
Date: 2026-11-10T12:00:41Z
New Revision: d08668f2835189f47b34e983f9be8f4003817dd5

URL: 
https://github.com/llvm/llvm-project/commit/d08668f2835189f47b34e983f9be8f4003817dd5
DIFF: 
https://github.com/llvm/llvm-project/commit/d08668f2835189f47b34e983f9be8f4003817dd5.diff

LOG: [InstCombine] Canonicalise Zero Vector operand to always be RHS of a 
shuffle vector (#237258)

shuffle zero, x, mask --> shuffle x, zero, mask'

Canonicalize ZeroVector of a shuffle to always be the RHS operand.
The motivation can be viewed in the next PR where the zero vector on the
RHS results in the same DAG, allowing for less patterns required for
instruction selection

Some riscv intrinsic test failed. This was due to the intrinsics
emitting shuffle vectors with a zero operand.

One of the intrinsics (ppaire) were not lowering correctly due to the
change. The reason being is that a function that checks whether we lower
to the intrinsic was dependent on whether the zero was a LHS operand or
RHS operand.

I modified this so that it checks both operand orders (via commuting the
mask). The function is only used for this one intrinsic so I am not
expecting any more regressions from this

Added: 
    

Modified: 
    clang/test/CodeGen/RISCV/rvp-intrinsics.c
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp
    llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
    llvm/test/Analysis/ValueTracking/knownbits-x86-hadd-hsub.ll
    llvm/test/CodeGen/RISCV/rvp-widening-convert.ll
    llvm/test/Transforms/InstCombine/insert-element-shuffle-vector-debugloc.ll
    llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
    llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
    llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
    llvm/test/Transforms/InstCombine/vec_shuffle.ll

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGen/RISCV/rvp-intrinsics.c 
b/clang/test/CodeGen/RISCV/rvp-intrinsics.c
index 8ceb7f054c78b6..c91f3b674ab407 100644
--- a/clang/test/CodeGen/RISCV/rvp-intrinsics.c
+++ b/clang/test/CodeGen/RISCV/rvp-intrinsics.c
@@ -6570,7 +6570,7 @@ int32x2_t test_pwmulsu_i32x2(int16x2_t rs1, uint16x2_t 
rs2) {
 // CHECK-SAME: i32 noundef [[RS1_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i32 [[RS1_COERCE]] to <4 x i8>
-// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <4 x i8> zeroinitializer, 
<4 x i8> [[TMP0]], <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, 
i32 7>
+// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <4 x i8> [[TMP0]], <4 x 
i8> zeroinitializer, <8 x i32> <i32 4, i32 0, i32 5, i32 1, i32 6, i32 2, i32 
7, i32 3>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <8 x i8> [[SHUFFLE_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //
@@ -6582,7 +6582,7 @@ int16x4_t test_pwcvth_i16x4(int8x4_t rs1) {
 // CHECK-SAME: i32 noundef [[RS1_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i32 [[RS1_COERCE]] to <4 x i8>
-// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <4 x i8> zeroinitializer, 
<4 x i8> [[TMP0]], <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, 
i32 7>
+// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <4 x i8> [[TMP0]], <4 x 
i8> zeroinitializer, <8 x i32> <i32 4, i32 0, i32 5, i32 1, i32 6, i32 2, i32 
7, i32 3>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <8 x i8> [[SHUFFLE_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //
@@ -6594,7 +6594,7 @@ uint16x4_t test_pwcvth_u16x4(uint8x4_t rs1) {
 // CHECK-SAME: i32 noundef [[RS1_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i32 [[RS1_COERCE]] to <2 x i16>
-// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <2 x i16> zeroinitializer, 
<2 x i16> [[TMP0]], <4 x i32> <i32 0, i32 2, i32 1, i32 3>
+// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <2 x i16> [[TMP0]], <2 x 
i16> zeroinitializer, <4 x i32> <i32 2, i32 0, i32 3, i32 1>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i16> [[SHUFFLE_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //
@@ -6606,7 +6606,7 @@ int32x2_t test_pwcvth_i32x2(int16x2_t rs1) {
 // CHECK-SAME: i32 noundef [[RS1_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i32 [[RS1_COERCE]] to <2 x i16>
-// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <2 x i16> zeroinitializer, 
<2 x i16> [[TMP0]], <4 x i32> <i32 0, i32 2, i32 1, i32 3>
+// CHECK-NEXT:    [[SHUFFLE_I:%.*]] = shufflevector <2 x i16> [[TMP0]], <2 x 
i16> zeroinitializer, <4 x i32> <i32 2, i32 0, i32 3, i32 1>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i16> [[SHUFFLE_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //
@@ -9819,7 +9819,7 @@ uint16x2_t test_pwunziphe_u16x2(uint8x4_t a) {
 // CHECK-SAME: i32 noundef [[A_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i32 [[A_COERCE]] to <4 x i8>
-// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i8> <i8 poison, i8 
0, i8 poison, i8 0>, <4 x i8> [[TMP0]], <4 x i32> <i32 1, i32 5, i32 3, i32 7>
+// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i8> [[TMP0]], <4 x 
i8> <i8 poison, i8 0, i8 poison, i8 0>, <4 x i32> <i32 5, i32 1, i32 7, i32 3>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i8> [[SHUFFLE_I_I]] to i32
 // CHECK-NEXT:    ret i32 [[TMP1]]
 //
@@ -9829,7 +9829,7 @@ int16x2_t test_pwunzipho_i16x2(int8x4_t a) { return 
__riscv_pwunzipho_i16x2(a);
 // CHECK-SAME: i32 noundef [[A_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i32 [[A_COERCE]] to <4 x i8>
-// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i8> <i8 poison, i8 
0, i8 poison, i8 0>, <4 x i8> [[TMP0]], <4 x i32> <i32 1, i32 5, i32 3, i32 7>
+// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i8> [[TMP0]], <4 x 
i8> <i8 poison, i8 0, i8 poison, i8 0>, <4 x i32> <i32 5, i32 1, i32 7, i32 3>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i8> [[SHUFFLE_I_I]] to i32
 // CHECK-NEXT:    ret i32 [[TMP1]]
 //
@@ -9953,7 +9953,7 @@ uint16x4_t test_pwunziphe_u16x4(uint8x8_t a) {
 // CHECK-SAME: i64 noundef [[A_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i64 [[A_COERCE]] to <8 x i8>
-// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> <i8 poison, i8 
0, i8 poison, i8 0, i8 poison, i8 0, i8 poison, i8 0>, <8 x i8> [[TMP0]], <8 x 
i32> <i32 1, i32 9, i32 3, i32 11, i32 5, i32 13, i32 7, i32 15>
+// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> [[TMP0]], <8 x 
i8> <i8 poison, i8 0, i8 poison, i8 0, i8 poison, i8 0, i8 poison, i8 0>, <8 x 
i32> <i32 9, i32 1, i32 11, i32 3, i32 13, i32 5, i32 15, i32 7>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <8 x i8> [[SHUFFLE_I_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //
@@ -9963,7 +9963,7 @@ int16x4_t test_pwunzipho_i16x4(int8x8_t a) { return 
__riscv_pwunzipho_i16x4(a);
 // CHECK-SAME: i64 noundef [[A_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i64 [[A_COERCE]] to <8 x i8>
-// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> <i8 poison, i8 
0, i8 poison, i8 0, i8 poison, i8 0, i8 poison, i8 0>, <8 x i8> [[TMP0]], <8 x 
i32> <i32 1, i32 9, i32 3, i32 11, i32 5, i32 13, i32 7, i32 15>
+// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <8 x i8> [[TMP0]], <8 x 
i8> <i8 poison, i8 0, i8 poison, i8 0, i8 poison, i8 0, i8 poison, i8 0>, <8 x 
i32> <i32 9, i32 1, i32 11, i32 3, i32 13, i32 5, i32 15, i32 7>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <8 x i8> [[SHUFFLE_I_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //
@@ -9997,7 +9997,7 @@ uint32x2_t test_pwunziphe_u32x2(uint16x4_t a) {
 // CHECK-SAME: i64 noundef [[A_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i64 [[A_COERCE]] to <4 x i16>
-// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> <i16 poison, 
i16 0, i16 poison, i16 0>, <4 x i16> [[TMP0]], <4 x i32> <i32 1, i32 5, i32 3, 
i32 7>
+// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> [[TMP0]], <4 x 
i16> <i16 poison, i16 0, i16 poison, i16 0>, <4 x i32> <i32 5, i32 1, i32 7, 
i32 3>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i16> [[SHUFFLE_I_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //
@@ -10007,7 +10007,7 @@ int32x2_t test_pwunzipho_i32x2(int16x4_t a) { return 
__riscv_pwunzipho_i32x2(a);
 // CHECK-SAME: i64 noundef [[A_COERCE:%.*]]) #[[ATTR0]] {
 // CHECK-NEXT:  [[ENTRY:.*:]]
 // CHECK-NEXT:    [[TMP0:%.*]] = bitcast i64 [[A_COERCE]] to <4 x i16>
-// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> <i16 poison, 
i16 0, i16 poison, i16 0>, <4 x i16> [[TMP0]], <4 x i32> <i32 1, i32 5, i32 3, 
i32 7>
+// CHECK-NEXT:    [[SHUFFLE_I_I:%.*]] = shufflevector <4 x i16> [[TMP0]], <4 x 
i16> <i16 poison, i16 0, i16 poison, i16 0>, <4 x i32> <i32 5, i32 1, i32 7, 
i32 3>
 // CHECK-NEXT:    [[TMP1:%.*]] = bitcast <4 x i16> [[SHUFFLE_I_I]] to i64
 // CHECK-NEXT:    ret i64 [[TMP1]]
 //

diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 9b7c412cf38e07..75e93fbfcd3640 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -7428,8 +7428,10 @@ bool 
RISCVTargetLowering::isVectorClearMaskLegal(ArrayRef<int> M,
   if (!Subtarget.hasStdExtP() || !VT.isSimple())
     return false;
   MVT SVT = VT.getSimpleVT();
+  SmallVector<int> CommutedMask(M);
+  ShuffleVectorSDNode::commuteMask(CommutedMask);
   return (SVT == MVT::v4i8 || SVT == MVT::v8i8 || SVT == MVT::v4i16) &&
-         isPackedZExtShuffleMask(M);
+         (isPackedZExtShuffleMask(M) || isPackedZExtShuffleMask(CommutedMask));
 }
 
 bool RISCVTargetLowering::isShuffleMaskLegal(ArrayRef<int> M, EVT VT) const {

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index e2307bcf0737d0..3e47f1032e5d4d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2446,10 +2446,12 @@ Instruction 
*InstCombinerImpl::foldSelectShuffle(ShuffleVectorInst &Shuf) {
   if (!Shuf.isSelect())
     return nullptr;
 
-  // Canonicalize to choose from operand 0 first unless operand 1 is undefined.
-  // Commuting undef to operand 0 conflicts with another canonicalization.
+  // Canonicalize to choose from operand 0 first unless operand 1 is
+  // undefined/zero. Commuting undef/zero to operand 0 conflicts with other
+  // canonicalization.
   unsigned NumElts = cast<FixedVectorType>(Shuf.getType())->getNumElements();
   if (!match(Shuf.getOperand(1), m_Undef()) &&
+      !match(Shuf.getOperand(1), m_CombineOr(m_Zero(), m_AnyZeroFP())) &&
       Shuf.getMaskValue(0) >= (int)NumElts) {
     // TODO: Can we assert that both operands of a shuffle-select are not undef
     // (otherwise, it would have been folded by instsimplify?
@@ -3068,6 +3070,12 @@ Instruction 
*InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
     return &SVI;
   }
 
+  // shuffle zero, x, mask --> shuffle x, zero, mask'
+  if (match(LHS, m_CombineOr(m_Zero(), m_AnyZeroFP())) && LHS != RHS) {
+    SVI.commute();
+    return &SVI;
+  }
+
   if (Instruction *I = canonicalizeInsertSplat(SVI, Builder))
     return I;
 

diff  --git a/llvm/test/Analysis/ValueTracking/knownbits-x86-hadd-hsub.ll 
b/llvm/test/Analysis/ValueTracking/knownbits-x86-hadd-hsub.ll
index 0d452829ae7578..89d4bc20c8ba9b 100644
--- a/llvm/test/Analysis/ValueTracking/knownbits-x86-hadd-hsub.ll
+++ b/llvm/test/Analysis/ValueTracking/knownbits-x86-hadd-hsub.ll
@@ -240,7 +240,7 @@ define <4 x i1> @hadd_shuffle_4th_negative_v4i32(<4 x i32> 
%x, <4 x i32> %y) {
 ; CHECK-NEXT:    [[TMP0:%.*]] = and <4 x i32> [[X]], splat (i32 3)
 ; CHECK-NEXT:    [[TMP1:%.*]] = and <4 x i32> [[Y]], <i32 3, i32 3, i32 -1, 
i32 -1>
 ; CHECK-NEXT:    [[TMP2:%.*]] = tail call <4 x i32> 
@llvm.x86.ssse3.phadd.d.128(<4 x i32> [[TMP0]], <4 x i32> [[TMP1]])
-; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <4 x i32> <i32 0, i32 0, i32 0, 
i32 poison>, <4 x i32> [[TMP2]], <4 x i32> <i32 0, i32 1, i32 2, i32 7>
+; CHECK-NEXT:    [[TMP3:%.*]] = shufflevector <4 x i32> [[TMP2]], <4 x i32> 
<i32 0, i32 0, i32 0, i32 poison>, <4 x i32> <i32 4, i32 5, i32 6, i32 3>
 ; CHECK-NEXT:    [[RET:%.*]] = icmp ne <4 x i32> [[TMP3]], splat (i32 8)
 ; CHECK-NEXT:    ret <4 x i1> [[RET]]
 ;

diff  --git a/llvm/test/CodeGen/RISCV/rvp-widening-convert.ll 
b/llvm/test/CodeGen/RISCV/rvp-widening-convert.ll
index e2f88d0757c00b..ebb38b30d141d6 100644
--- a/llvm/test/CodeGen/RISCV/rvp-widening-convert.ll
+++ b/llvm/test/CodeGen/RISCV/rvp-widening-convert.ll
@@ -76,7 +76,7 @@ define <4 x i16> @test_pwcvth_v4i8(<4 x i8> %a) {
 ; RV64:       # %bb.0:
 ; RV64-NEXT:    pwcvth.wb a0, a0
 ; RV64-NEXT:    ret
-  %shuffle = shufflevector <4 x i8> zeroinitializer, <4 x i8> %a, <8 x i32> 
<i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>
+  %shuffle = shufflevector <4 x i8> %a, <4 x i8> zeroinitializer, <8 x i32> 
<i32 4, i32 0, i32 5, i32 1, i32 6, i32 2, i32 7, i32 3>
   %res = bitcast <8 x i8> %shuffle to <4 x i16>
   ret <4 x i16> %res
 }

diff  --git 
a/llvm/test/Transforms/InstCombine/insert-element-shuffle-vector-debugloc.ll 
b/llvm/test/Transforms/InstCombine/insert-element-shuffle-vector-debugloc.ll
index eb115820f34d8d..3276391127e309 100644
--- a/llvm/test/Transforms/InstCombine/insert-element-shuffle-vector-debugloc.ll
+++ b/llvm/test/Transforms/InstCombine/insert-element-shuffle-vector-debugloc.ll
@@ -16,7 +16,7 @@ define <4 x float> @widget(ptr %arg) !dbg !5 {
 ; CHECK-NEXT:  [[BB:.*:]]
 ; CHECK-NEXT:    [[LOAD:%.*]] = load <2 x float>, ptr [[ARG]], align 4, !dbg 
[[DBG8:![0-9]+]]
 ; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <2 x float> [[LOAD]], <2 x 
float> poison, <4 x i32> <i32 0, i32 poison, i32 poison, i32 poison>, !dbg 
[[DBG8]]
-; CHECK-NEXT:    [[INSERTELEMENT:%.*]] = shufflevector <4 x float> <float 
0.000000e+00, float poison, float poison, float poison>, <4 x float> [[TMP0]], 
<4 x i32> <i32 4, i32 0, i32 0, i32 0>, !dbg [[DBG9:![0-9]+]]
+; CHECK-NEXT:    [[INSERTELEMENT:%.*]] = shufflevector <4 x float> [[TMP0]], 
<4 x float> <float 0.000000e+00, float poison, float poison, float poison>, <4 
x i32> <i32 0, i32 4, i32 4, i32 4>, !dbg [[DBG9:![0-9]+]]
 ; CHECK-NEXT:    ret <4 x float> [[INSERTELEMENT]], !dbg [[DBG10:![0-9]+]]
 ;
 bb:

diff  --git 
a/llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll 
b/llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
index 8bc915e695aa75..ab4655baa5b0af 100644
--- a/llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/insert-extract-shuffle-inseltpoison.ll
@@ -87,7 +87,7 @@ define <8 x float> @widen_extract4(<8 x float> %ins, <2 x 
float> %ext) {
 define <8 x i16> @pr26015(<4 x i16> %t0) {
 ; CHECK-LABEL: @pr26015(
 ; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <4 x i16> [[T0:%.*]], <4 x i16> 
poison, <8 x i32> <i32 poison, i32 poison, i32 2, i32 3, i32 poison, i32 
poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[T5:%.*]] = shufflevector <8 x i16> <i16 0, i16 0, i16 0, 
i16 poison, i16 0, i16 0, i16 0, i16 poison>, <8 x i16> [[TMP1]], <8 x i32> 
<i32 0, i32 1, i32 2, i32 10, i32 4, i32 5, i32 6, i32 11>
+; CHECK-NEXT:    [[T5:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> <i16 
0, i16 0, i16 0, i16 poison, i16 0, i16 0, i16 0, i16 poison>, <8 x i32> <i32 
8, i32 9, i32 10, i32 2, i32 12, i32 13, i32 14, i32 3>
 ; CHECK-NEXT:    ret <8 x i16> [[T5]]
 ;
   %t1 = extractelement <4 x i16> %t0, i32 2
@@ -267,7 +267,7 @@ define <4 x i32> @extractelt_insertion(<2 x i32> %x, i32 
%y) {
 ; CHECK-LABEL: @extractelt_insertion(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> 
poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
-; CHECK-NEXT:    [[B:%.*]] = shufflevector <4 x i32> <i32 0, i32 poison, i32 
poison, i32 poison>, <4 x i32> [[TMP0]], <4 x i32> <i32 0, i32 0, i32 0, i32 5>
+; CHECK-NEXT:    [[B:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> <i32 
0, i32 poison, i32 poison, i32 poison>, <4 x i32> <i32 4, i32 4, i32 4, i32 1>
 ; CHECK-NEXT:    [[C:%.*]] = add i32 [[Y:%.*]], 3
 ; CHECK-NEXT:    [[D:%.*]] = extractelement <4 x i32> [[TMP0]], i32 [[C]]
 ; CHECK-NEXT:    [[E:%.*]] = icmp eq i32 [[D]], 0

diff  --git a/llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll 
b/llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
index e4eacbc1f54be5..73ba304d48c749 100644
--- a/llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/insert-extract-shuffle.ll
@@ -87,7 +87,7 @@ define <8 x float> @widen_extract4(<8 x float> %ins, <2 x 
float> %ext) {
 define <8 x i16> @pr26015(<4 x i16> %t0) {
 ; CHECK-LABEL: @pr26015(
 ; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <4 x i16> [[T0:%.*]], <4 x i16> 
poison, <8 x i32> <i32 poison, i32 poison, i32 2, i32 3, i32 poison, i32 
poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[T5:%.*]] = shufflevector <8 x i16> <i16 0, i16 0, i16 0, 
i16 poison, i16 0, i16 0, i16 0, i16 poison>, <8 x i16> [[TMP1]], <8 x i32> 
<i32 0, i32 1, i32 2, i32 10, i32 4, i32 5, i32 6, i32 11>
+; CHECK-NEXT:    [[T5:%.*]] = shufflevector <8 x i16> [[TMP1]], <8 x i16> <i16 
0, i16 0, i16 0, i16 poison, i16 0, i16 0, i16 0, i16 poison>, <8 x i32> <i32 
8, i32 9, i32 10, i32 2, i32 12, i32 13, i32 14, i32 3>
 ; CHECK-NEXT:    ret <8 x i16> [[T5]]
 ;
   %t1 = extractelement <4 x i16> %t0, i32 2
@@ -267,7 +267,7 @@ define <4 x i32> @extractelt_insertion(<2 x i32> %x, i32 
%y) {
 ; CHECK-LABEL: @extractelt_insertion(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TMP0:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> 
poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
-; CHECK-NEXT:    [[B:%.*]] = shufflevector <4 x i32> <i32 0, i32 poison, i32 
poison, i32 poison>, <4 x i32> [[TMP0]], <4 x i32> <i32 0, i32 0, i32 0, i32 5>
+; CHECK-NEXT:    [[B:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> <i32 
0, i32 poison, i32 poison, i32 poison>, <4 x i32> <i32 4, i32 4, i32 4, i32 1>
 ; CHECK-NEXT:    [[C:%.*]] = add i32 [[Y:%.*]], 3
 ; CHECK-NEXT:    [[D:%.*]] = extractelement <4 x i32> [[TMP0]], i32 [[C]]
 ; CHECK-NEXT:    [[E:%.*]] = icmp eq i32 [[D]], 0
@@ -795,7 +795,7 @@ define <4 x i32> @infloop_D151807(<4 x float> %arg) {
 ; CHECK-NEXT:    [[I:%.*]] = shufflevector <4 x float> [[ARG:%.*]], <4 x 
float> poison, <2 x i32> <i32 2, i32 poison>
 ; CHECK-NEXT:    [[I1:%.*]] = bitcast <2 x float> [[I]] to <2 x i32>
 ; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <2 x i32> [[I1]], <2 x i32> 
poison, <4 x i32> <i32 0, i32 poison, i32 poison, i32 poison>
-; CHECK-NEXT:    [[I4:%.*]] = shufflevector <4 x i32> <i32 0, i32 poison, i32 
poison, i32 poison>, <4 x i32> [[TMP1]], <4 x i32> <i32 4, i32 0, i32 0, i32 0>
+; CHECK-NEXT:    [[I4:%.*]] = shufflevector <4 x i32> [[TMP1]], <4 x i32> <i32 
0, i32 poison, i32 poison, i32 poison>, <4 x i32> <i32 0, i32 4, i32 4, i32 4>
 ; CHECK-NEXT:    ret <4 x i32> [[I4]]
 ;
   %i = shufflevector <4 x float> %arg, <4 x float> poison, <2 x i32> <i32 2, 
i32 poison>
@@ -856,7 +856,7 @@ bb12:
 ; Insert into an integer zero vector
 define <4 x i32> @insert_into_integer_zero_vector(<4 x i32> %vec) {
 ; CHECK-LABEL: @insert_into_integer_zero_vector(
-; CHECK-NEXT:    [[VECINS:%.*]] = shufflevector <4 x i32> <i32 0, i32 poison, 
i32 poison, i32 poison>, <4 x i32> [[VEC:%.*]], <4 x i32> <i32 4, i32 0, i32 0, 
i32 0>
+; CHECK-NEXT:    [[VECINS:%.*]] = shufflevector <4 x i32> [[VEC:%.*]], <4 x 
i32> <i32 0, i32 poison, i32 poison, i32 poison>, <4 x i32> <i32 0, i32 4, i32 
4, i32 4>
 ; CHECK-NEXT:    ret <4 x i32> [[VECINS]]
 ;
   %vecext = extractelement <4 x i32> %vec, i32 0
@@ -867,7 +867,7 @@ define <4 x i32> @insert_into_integer_zero_vector(<4 x i32> 
%vec) {
 ; Insert into an float zero vector
 define <4 x float> @insert_into_float_zero_vector(<4 x float> %vec) {
 ; CHECK-LABEL: @insert_into_float_zero_vector(
-; CHECK-NEXT:    [[VECINS:%.*]] = shufflevector <4 x float> <float 
0.000000e+00, float poison, float poison, float poison>, <4 x float> 
[[VEC:%.*]], <4 x i32> <i32 4, i32 0, i32 0, i32 0>
+; CHECK-NEXT:    [[VECINS:%.*]] = shufflevector <4 x float> [[VEC:%.*]], <4 x 
float> <float 0.000000e+00, float poison, float poison, float poison>, <4 x 
i32> <i32 0, i32 4, i32 4, i32 4>
 ; CHECK-NEXT:    ret <4 x float> [[VECINS]]
 ;
   %vecext = extractelement <4 x float> %vec, i32 0
@@ -878,7 +878,7 @@ define <4 x float> @insert_into_float_zero_vector(<4 x 
float> %vec) {
 ; Insert into an null ptr vector
 define <4 x ptr> @insert_into_null_ptr_vector(<4 x ptr> %vec) {
 ; CHECK-LABEL: @insert_into_null_ptr_vector(
-; CHECK-NEXT:    [[VECINS:%.*]] = shufflevector <4 x ptr> <ptr null, ptr 
poison, ptr poison, ptr poison>, <4 x ptr> [[VEC:%.*]], <4 x i32> <i32 4, i32 
0, i32 0, i32 0>
+; CHECK-NEXT:    [[VECINS:%.*]] = shufflevector <4 x ptr> [[VEC:%.*]], <4 x 
ptr> <ptr null, ptr poison, ptr poison, ptr poison>, <4 x i32> <i32 0, i32 4, 
i32 4, i32 4>
 ; CHECK-NEXT:    ret <4 x ptr> [[VECINS]]
 ;
   %vecext = extractelement <4 x ptr> %vec, i32 0

diff  --git a/llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll 
b/llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
index ded7b7b5f2a399..63de1039a9c349 100644
--- a/llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/vec_shuffle-inseltpoison.ll
@@ -1346,7 +1346,7 @@ define <2 x float> @frem_splat_constant1(<2 x float> %x) {
 
 define <2 x i1> @PR40734(<1 x i1> %x, <4 x i1> %y) {
 ; CHECK-LABEL: @PR40734(
-; CHECK-NEXT:    [[WIDEN:%.*]] = shufflevector <1 x i1> zeroinitializer, <1 x 
i1> [[X:%.*]], <2 x i32> <i32 0, i32 1>
+; CHECK-NEXT:    [[WIDEN:%.*]] = shufflevector <1 x i1> [[X:%.*]], <1 x i1> 
zeroinitializer, <2 x i32> <i32 1, i32 0>
 ; CHECK-NEXT:    [[NARROW:%.*]] = shufflevector <4 x i1> [[Y:%.*]], <4 x i1> 
poison, <2 x i32> <i32 0, i32 1>
 ; CHECK-NEXT:    [[R:%.*]] = and <2 x i1> [[WIDEN]], [[NARROW]]
 ; CHECK-NEXT:    ret <2 x i1> [[R]]

diff  --git a/llvm/test/Transforms/InstCombine/vec_shuffle.ll 
b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
index 95a680c0409451..6da86a86a1267a 100644
--- a/llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -1461,7 +1461,7 @@ define <2 x float> @frem_splat_constant1(<2 x float> %x) {
 
 define <2 x i1> @PR40734(<1 x i1> %x, <4 x i1> %y) {
 ; CHECK-LABEL: @PR40734(
-; CHECK-NEXT:    [[WIDEN:%.*]] = shufflevector <1 x i1> zeroinitializer, <1 x 
i1> [[X:%.*]], <2 x i32> <i32 0, i32 1>
+; CHECK-NEXT:    [[WIDEN:%.*]] = shufflevector <1 x i1> [[X:%.*]], <1 x i1> 
zeroinitializer, <2 x i32> <i32 1, i32 0>
 ; CHECK-NEXT:    [[NARROW:%.*]] = shufflevector <4 x i1> [[Y:%.*]], <4 x i1> 
poison, <2 x i32> <i32 0, i32 1>
 ; CHECK-NEXT:    [[R:%.*]] = and <2 x i1> [[WIDEN]], [[NARROW]]
 ; CHECK-NEXT:    ret <2 x i1> [[R]]
@@ -2567,3 +2567,41 @@ loop:
 exit:
   ret <4 x i32> %shuf1
 }
+
+; Canonicalise the zero vec to the RHS
+
+define <4 x i32> @canonical_zero_vec_rhs(<4 x i32> %x) {
+; CHECK-LABEL: @canonical_zero_vec_rhs(
+; CHECK-NEXT:    [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> 
<i32 poison, i32 0, i32 0, i32 0>, <4 x i32> <i32 0, i32 5, i32 6, i32 7>
+; CHECK-NEXT:    ret <4 x i32> [[SHUF]]
+;
+  %shuf = shufflevector <4 x i32> %x, <4 x i32> zeroinitializer, <4 x i32> 
<i32 0, i32 5, i32 6, i32 7>
+  ret <4 x i32> %shuf
+}
+
+define <8 x half> @zero_vec_lhs(<8 x half> %x) {
+; CHECK-LABEL: @zero_vec_lhs(
+; CHECK-NEXT:    [[SHUF:%.*]] = shufflevector <8 x half> [[X:%.*]], <8 x half> 
<half 0.000000e+00, half 0.000000e+00, half 0.000000e+00, half 0.000000e+00, 
half 0.000000e+00, half 0.000000e+00, half 0.000000e+00, half poison>, <8 x 
i32> <i32 0, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14>
+; CHECK-NEXT:    ret <8 x half> [[SHUF]]
+;
+  %shuf = shufflevector <8 x half> zeroinitializer, <8 x half> %x, <8 x i32> 
<i32 8, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6>
+  ret <8 x half> %shuf
+}
+
+define <4 x i8> @zero_vec_poison(<4 x i8> %x) {
+; CHECK-LABEL: @zero_vec_poison(
+; CHECK-NEXT:    [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> <i8 
poison, i8 0, i8 0, i8 0>, <4 x i32> <i32 5, i32 6, i32 7, i32 0>
+; CHECK-NEXT:    ret <4 x i8> [[SHUF]]
+;
+  %shuf = shufflevector <4 x i8> <i8 poison, i8 0, i8 0, i8 0>, <4 x i8> %x,  
<4 x i32> <i32 1, i32 2, i32 3, i32 4>
+  ret <4 x i8> %shuf
+}
+
+define <4 x i8> @zero_vec_poison_select(<4 x i8> %x) {
+; CHECK-LABEL: @zero_vec_poison_select(
+; CHECK-NEXT:    [[SHUF:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> <i8 
poison, i8 0, i8 0, i8 poison>, <4 x i32> <i32 poison, i32 5, i32 6, i32 0>
+; CHECK-NEXT:    ret <4 x i8> [[SHUF]]
+;
+  %shuf = shufflevector <4 x i8> <i8 poison, i8 0, i8 0, i8 0>, <4 x i8> %x,  
<4 x i32> <i32 0, i32 1, i32 2, i32 4>
+  ret <4 x i8> %shuf
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to