[llvm] [VectorCombine][AMDGPU] Narrow Phi of Shuffles. (PR #140188)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 04:17:48 PDT 2025


================
@@ -0,0 +1,2997 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -mtriple=x86_64-- -mcpu=x86-64 -passes=vector-combine -S %s | FileCheck %s --check-prefixes=CHECK-V1
+; RUN: opt -mtriple=x86_64-- -mcpu=x86-64-v2 -passes=vector-combine -S %s | FileCheck %s --check-prefixes=CHECK-V2
+; RUN: opt -mtriple=x86_64-- -mcpu=x86-64-v3 -passes=vector-combine -S %s | FileCheck %s --check-prefixes=CHECK-V3
+; RUN: opt -mtriple=x86_64-- -mcpu=x86-64-v4 -passes=vector-combine -S %s | FileCheck %s --check-prefixes=CHECK-V4
+
+define <2 x i8> @shuffle_v2i8(<2 x i8> %arg0, i1 %cond) {
+; CHECK-V1-LABEL: define <2 x i8> @shuffle_v2i8(
+; CHECK-V1-SAME: <2 x i8> [[ARG0:%.*]], i1 [[COND:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-V1-NEXT:  [[ENTRY:.*:]]
+; CHECK-V1-NEXT:    br i1 [[COND]], label %[[THEN:.*]], label %[[ELSE:.*]]
+; CHECK-V1:       [[THEN]]:
+; CHECK-V1-NEXT:    [[VAL1:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 1, i32 1>
+; CHECK-V1-NEXT:    tail call void @func0()
+; CHECK-V1-NEXT:    br label %[[FINALLY:.*]]
+; CHECK-V1:       [[ELSE]]:
+; CHECK-V1-NEXT:    [[VAL2:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 2, i32 2>
+; CHECK-V1-NEXT:    tail call void @func1()
+; CHECK-V1-NEXT:    br label %[[FINALLY]]
+; CHECK-V1:       [[FINALLY]]:
+; CHECK-V1-NEXT:    [[VAL3:%.*]] = phi <2 x i8> [ [[VAL1]], %[[THEN]] ], [ [[VAL2]], %[[ELSE]] ]
+; CHECK-V1-NEXT:    ret <2 x i8> [[VAL3]]
+;
+; CHECK-V2-LABEL: define <2 x i8> @shuffle_v2i8(
+; CHECK-V2-SAME: <2 x i8> [[ARG0:%.*]], i1 [[COND:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-V2-NEXT:  [[ENTRY:.*:]]
+; CHECK-V2-NEXT:    br i1 [[COND]], label %[[THEN:.*]], label %[[ELSE:.*]]
+; CHECK-V2:       [[THEN]]:
+; CHECK-V2-NEXT:    [[VAL1:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 1, i32 1>
+; CHECK-V2-NEXT:    tail call void @func0()
+; CHECK-V2-NEXT:    br label %[[FINALLY:.*]]
+; CHECK-V2:       [[ELSE]]:
+; CHECK-V2-NEXT:    [[VAL2:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 2, i32 2>
+; CHECK-V2-NEXT:    tail call void @func1()
+; CHECK-V2-NEXT:    br label %[[FINALLY]]
+; CHECK-V2:       [[FINALLY]]:
+; CHECK-V2-NEXT:    [[VAL3:%.*]] = phi <2 x i8> [ [[VAL1]], %[[THEN]] ], [ [[VAL2]], %[[ELSE]] ]
+; CHECK-V2-NEXT:    ret <2 x i8> [[VAL3]]
+;
+; CHECK-V3-LABEL: define <2 x i8> @shuffle_v2i8(
+; CHECK-V3-SAME: <2 x i8> [[ARG0:%.*]], i1 [[COND:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-V3-NEXT:  [[ENTRY:.*:]]
+; CHECK-V3-NEXT:    br i1 [[COND]], label %[[THEN:.*]], label %[[ELSE:.*]]
+; CHECK-V3:       [[THEN]]:
+; CHECK-V3-NEXT:    [[VAL1:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 1, i32 1>
+; CHECK-V3-NEXT:    tail call void @func0()
+; CHECK-V3-NEXT:    br label %[[FINALLY:.*]]
+; CHECK-V3:       [[ELSE]]:
+; CHECK-V3-NEXT:    [[VAL2:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 2, i32 2>
+; CHECK-V3-NEXT:    tail call void @func1()
+; CHECK-V3-NEXT:    br label %[[FINALLY]]
+; CHECK-V3:       [[FINALLY]]:
+; CHECK-V3-NEXT:    [[VAL3:%.*]] = phi <2 x i8> [ [[VAL1]], %[[THEN]] ], [ [[VAL2]], %[[ELSE]] ]
+; CHECK-V3-NEXT:    ret <2 x i8> [[VAL3]]
+;
+; CHECK-V4-LABEL: define <2 x i8> @shuffle_v2i8(
+; CHECK-V4-SAME: <2 x i8> [[ARG0:%.*]], i1 [[COND:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-V4-NEXT:  [[ENTRY:.*:]]
+; CHECK-V4-NEXT:    br i1 [[COND]], label %[[THEN:.*]], label %[[ELSE:.*]]
+; CHECK-V4:       [[THEN]]:
+; CHECK-V4-NEXT:    [[VAL1:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 1, i32 1>
+; CHECK-V4-NEXT:    tail call void @func0()
+; CHECK-V4-NEXT:    br label %[[FINALLY:.*]]
+; CHECK-V4:       [[ELSE]]:
+; CHECK-V4-NEXT:    [[VAL2:%.*]] = shufflevector <2 x i8> [[ARG0]], <2 x i8> poison, <2 x i32> <i32 2, i32 2>
+; CHECK-V4-NEXT:    tail call void @func1()
+; CHECK-V4-NEXT:    br label %[[FINALLY]]
+; CHECK-V4:       [[FINALLY]]:
+; CHECK-V4-NEXT:    [[VAL3:%.*]] = phi <2 x i8> [ [[VAL1]], %[[THEN]] ], [ [[VAL2]], %[[ELSE]] ]
+; CHECK-V4-NEXT:    ret <2 x i8> [[VAL3]]
+;
+entry:
+  br i1 %cond, label %then, label %else
+
+then:
+  %val1 = shufflevector <2 x i8> %arg0, <2 x i8> poison, <2 x i32> <i32 1, i32 1>
+  tail call void @func0()
+  br label %finally
+
+else:
+  %val2 = shufflevector <2 x i8> %arg0, <2 x i8> poison, <2 x i32> <i32 2, i32 2>
+  tail call void @func1()
+  br label %finally
+
+finally:
+  %val3 = phi <2 x i8> [ %val1, %then ], [ %val2, %else ]
+  ret <2 x i8> %val3
+}
+
+define <4 x i8> @shuffle_v4i8(<3 x i8> %arg0, i1 %cond) {
----------------
RKSimon wrote:

Should the arg be <4  x i8>?

https://github.com/llvm/llvm-project/pull/140188


More information about the llvm-commits mailing list