https://github.com/kieroxide updated https://github.com/llvm/llvm-project/pull/237258
>From 56210ed433283baacd489033810a37f79a2bc507 Mon Sep 17 00:00:00 2001 From: Kieran Bailey <[email protected]> Date: Mon, 2 Nov 2026 15:34:28 +0000 Subject: [PATCH 1/3] [InstCombine] Canonicalise Vector Shuffle that clears upper bits Currently, shuffle vectors that are equivalent to preserving lane 0 and clearing the uppers lanes of a vector result in different shuffle vectors and masks Recognise and canonicalise the shuffleVectors to the same form allowing for easier recognition in the backend --- .../InstCombine/InstCombineVectorOps.cpp | 12 +++++- .../Transforms/InstCombine/vec_shuffle.ll | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) 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/Transforms/InstCombine/vec_shuffle.ll b/llvm/test/Transforms/InstCombine/vec_shuffle.ll index 95a680c0409451..8fedfac8f21899 100644 --- a/llvm/test/Transforms/InstCombine/vec_shuffle.ll +++ b/llvm/test/Transforms/InstCombine/vec_shuffle.ll @@ -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> <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 half> [[X:%.*]], <8 x i32> <i32 8, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6> +; 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> <i8 poison, i8 0, i8 0, i8 0>, <4 x i8> [[X:%.*]], <4 x i32> <i32 1, i32 2, i32 3, i32 4> +; 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> <i8 poison, i8 0, i8 0, i8 poison>, <4 x i8> [[X:%.*]], <4 x i32> <i32 poison, i32 1, i32 2, i32 4> +; 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 +} >From 69d6bf5e5261aee2eacbf0643378cd87cb5f8970 Mon Sep 17 00:00:00 2001 From: Kieran Bailey <[email protected]> Date: Mon, 2 Nov 2026 15:34:53 +0000 Subject: [PATCH 2/3] Update test checks --- .../ValueTracking/knownbits-x86-hadd-hsub.ll | 2 +- .../insert-element-shuffle-vector-debugloc.ll | 2 +- .../insert-extract-shuffle-inseltpoison.ll | 4 ++-- .../Transforms/InstCombine/insert-extract-shuffle.ll | 12 ++++++------ .../InstCombine/vec_shuffle-inseltpoison.ll | 2 +- llvm/test/Transforms/InstCombine/vec_shuffle.ll | 8 ++++---- 6 files changed, 15 insertions(+), 15 deletions(-) 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/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 8fedfac8f21899..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]] @@ -2581,7 +2581,7 @@ define <4 x i32> @canonical_zero_vec_rhs(<4 x i32> %x) { define <8 x half> @zero_vec_lhs(<8 x half> %x) { ; CHECK-LABEL: @zero_vec_lhs( -; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <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 half> [[X:%.*]], <8 x i32> <i32 8, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6> +; 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> @@ -2590,7 +2590,7 @@ define <8 x half> @zero_vec_lhs(<8 x half> %x) { define <4 x i8> @zero_vec_poison(<4 x i8> %x) { ; CHECK-LABEL: @zero_vec_poison( -; CHECK-NEXT: [[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> +; 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> @@ -2599,7 +2599,7 @@ define <4 x i8> @zero_vec_poison(<4 x i8> %x) { 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> <i8 poison, i8 0, i8 0, i8 poison>, <4 x i8> [[X:%.*]], <4 x i32> <i32 poison, i32 1, i32 2, i32 4> +; 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> >From d88a44642e7cca841992ba5124e9f81d35a41804 Mon Sep 17 00:00:00 2001 From: Kieran Bailey <[email protected]> Date: Mon, 9 Nov 2026 09:23:04 +0000 Subject: [PATCH 3/3] Fix riscv intrinsic regression --- clang/test/CodeGen/RISCV/rvp-intrinsics.c | 20 +++++++++---------- .../CodeGen/RISCV/rvp-widening-convert.ll | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/test/CodeGen/RISCV/rvp-intrinsics.c b/clang/test/CodeGen/RISCV/rvp-intrinsics.c index 409c4999edd233..084272cf27b814 100644 --- a/clang/test/CodeGen/RISCV/rvp-intrinsics.c +++ b/clang/test/CodeGen/RISCV/rvp-intrinsics.c @@ -6554,7 +6554,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]] // @@ -6566,7 +6566,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]] // @@ -6578,7 +6578,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]] // @@ -6590,7 +6590,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]] // @@ -9803,7 +9803,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]] // @@ -9813,7 +9813,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]] // @@ -9937,7 +9937,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]] // @@ -9947,7 +9947,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]] // @@ -9981,7 +9981,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]] // @@ -9991,7 +9991,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/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 } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
