[llvm] [NFC][SLP] Precommit tests for the phantom load saving (PR #228901)
Dmitry Sidorov via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 4 17:21:06 PDT 2026
================
@@ -0,0 +1,527 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgpu9.0a-amd-amdhsa < %s | FileCheck %s --check-prefixes=CHECK,GFX9,GFX90A
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgpu9.42-amd-amdhsa < %s | FileCheck %s --check-prefixes=CHECK,GFX9,GFX942-950,GFX942
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgpu9.50-amd-amdhsa < %s | FileCheck %s --check-prefixes=CHECK,GFX9,GFX942-950,GFX950
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgpu10.30-amd-amdhsa < %s | FileCheck %s --check-prefixes=CHECK,GFX1030
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgpu12.50-amd-amdhsa < %s | FileCheck %s --check-prefixes=CHECK,GFX1250
+
+; Integer reductions over consecutive byte loads that are widened before
+; the arithmetic. The scalar byte loads already coalesce into one wide
+; load per pointer, so a vector load bundle saves nothing, and once that
+; saving is charged neither the dot product nor the sum is profitable.
+; Vectorized on gfx90a, the dot product of eight sign extended bytes grew
+; from 8 to 23 instructions and the sum of four zero extended bytes from
+; 8 to 14. The and reduction stays vectorized because its zero extension
+; folds away and the vector form works on the bytes as loaded.
+; Lanes of 16 bits are packed two to a register, so the sum into i16 lanes
+; and the dot product of i16 loads keep their saving and stay vectorized.
+
+define i32 @dot8_sext_i8(ptr addrspace(1) %a, ptr addrspace(1) %b) {
+; CHECK-LABEL: define i32 @dot8_sext_i8(
+; CHECK-SAME: ptr addrspace(1) [[A:%.*]], ptr addrspace(1) [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[A]], i32 0
+; CHECK-NEXT: [[PB0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[B]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i8>, ptr addrspace(1) [[PA0]], align 1
+; CHECK-NEXT: [[TMP1:%.*]] = sext <4 x i8> [[TMP0]] to <4 x i32>
+; CHECK-NEXT: [[TMP2:%.*]] = load <4 x i8>, ptr addrspace(1) [[PB0]], align 1
+; CHECK-NEXT: [[TMP3:%.*]] = sext <4 x i8> [[TMP2]] to <4 x i32>
+; CHECK-NEXT: [[TMP4:%.*]] = mul nsw <4 x i32> [[TMP1]], [[TMP3]]
+; CHECK-NEXT: [[PA4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[A]], i32 4
+; CHECK-NEXT: [[PB4:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[B]], i32 4
+; CHECK-NEXT: [[TMP5:%.*]] = load <4 x i8>, ptr addrspace(1) [[PA4]], align 1
+; CHECK-NEXT: [[TMP6:%.*]] = sext <4 x i8> [[TMP5]] to <4 x i32>
+; CHECK-NEXT: [[TMP7:%.*]] = load <4 x i8>, ptr addrspace(1) [[PB4]], align 1
+; CHECK-NEXT: [[TMP8:%.*]] = sext <4 x i8> [[TMP7]] to <4 x i32>
+; CHECK-NEXT: [[TMP9:%.*]] = mul nsw <4 x i32> [[TMP6]], [[TMP8]]
+; CHECK-NEXT: [[RDX_OP:%.*]] = add <4 x i32> [[TMP4]], [[TMP9]]
+; CHECK-NEXT: [[R7:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[RDX_OP]])
+; CHECK-NEXT: ret i32 [[R7]]
+;
+entry:
+ %pa0 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 0
+ %la0 = load i8, ptr addrspace(1) %pa0, align 1
+ %xa0 = sext i8 %la0 to i32
+ %pb0 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 0
+ %lb0 = load i8, ptr addrspace(1) %pb0, align 1
+ %xb0 = sext i8 %lb0 to i32
+ %m0 = mul nsw i32 %xa0, %xb0
+ %pa1 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 1
+ %la1 = load i8, ptr addrspace(1) %pa1, align 1
+ %xa1 = sext i8 %la1 to i32
+ %pb1 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 1
+ %lb1 = load i8, ptr addrspace(1) %pb1, align 1
+ %xb1 = sext i8 %lb1 to i32
+ %m1 = mul nsw i32 %xa1, %xb1
+ %r1 = add nsw i32 %m0, %m1
+ %pa2 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 2
+ %la2 = load i8, ptr addrspace(1) %pa2, align 1
+ %xa2 = sext i8 %la2 to i32
+ %pb2 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 2
+ %lb2 = load i8, ptr addrspace(1) %pb2, align 1
+ %xb2 = sext i8 %lb2 to i32
+ %m2 = mul nsw i32 %xa2, %xb2
+ %r2 = add nsw i32 %r1, %m2
+ %pa3 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 3
+ %la3 = load i8, ptr addrspace(1) %pa3, align 1
+ %xa3 = sext i8 %la3 to i32
+ %pb3 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 3
+ %lb3 = load i8, ptr addrspace(1) %pb3, align 1
+ %xb3 = sext i8 %lb3 to i32
+ %m3 = mul nsw i32 %xa3, %xb3
+ %r3 = add nsw i32 %r2, %m3
+ %pa4 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 4
+ %la4 = load i8, ptr addrspace(1) %pa4, align 1
+ %xa4 = sext i8 %la4 to i32
+ %pb4 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 4
+ %lb4 = load i8, ptr addrspace(1) %pb4, align 1
+ %xb4 = sext i8 %lb4 to i32
+ %m4 = mul nsw i32 %xa4, %xb4
+ %r4 = add nsw i32 %r3, %m4
+ %pa5 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 5
+ %la5 = load i8, ptr addrspace(1) %pa5, align 1
+ %xa5 = sext i8 %la5 to i32
+ %pb5 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 5
+ %lb5 = load i8, ptr addrspace(1) %pb5, align 1
+ %xb5 = sext i8 %lb5 to i32
+ %m5 = mul nsw i32 %xa5, %xb5
+ %r5 = add nsw i32 %r4, %m5
+ %pa6 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 6
+ %la6 = load i8, ptr addrspace(1) %pa6, align 1
+ %xa6 = sext i8 %la6 to i32
+ %pb6 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 6
+ %lb6 = load i8, ptr addrspace(1) %pb6, align 1
+ %xb6 = sext i8 %lb6 to i32
+ %m6 = mul nsw i32 %xa6, %xb6
+ %r6 = add nsw i32 %r5, %m6
+ %pa7 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 7
+ %la7 = load i8, ptr addrspace(1) %pa7, align 1
+ %xa7 = sext i8 %la7 to i32
+ %pb7 = getelementptr inbounds i8, ptr addrspace(1) %b, i32 7
+ %lb7 = load i8, ptr addrspace(1) %pb7, align 1
+ %xb7 = sext i8 %lb7 to i32
+ %m7 = mul nsw i32 %xa7, %xb7
+ %r7 = add nsw i32 %r6, %m7
+ ret i32 %r7
+}
+
+define i32 @sum4_zext_i8(ptr addrspace(1) %a) {
+; CHECK-LABEL: define i32 @sum4_zext_i8(
+; CHECK-SAME: ptr addrspace(1) [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[A]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i8>, ptr addrspace(1) [[PA0]], align 1
+; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i8> [[TMP0]] to <4 x i16>
+; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[TMP1]])
+; CHECK-NEXT: [[R3:%.*]] = zext i16 [[TMP2]] to i32
+; CHECK-NEXT: ret i32 [[R3]]
+;
+entry:
+ %pa0 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 0
+ %la0 = load i8, ptr addrspace(1) %pa0, align 1
+ %xa0 = zext i8 %la0 to i32
+ %pa1 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 1
+ %la1 = load i8, ptr addrspace(1) %pa1, align 1
+ %xa1 = zext i8 %la1 to i32
+ %r1 = add nsw i32 %xa0, %xa1
+ %pa2 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 2
+ %la2 = load i8, ptr addrspace(1) %pa2, align 1
+ %xa2 = zext i8 %la2 to i32
+ %r2 = add nsw i32 %r1, %xa2
+ %pa3 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 3
+ %la3 = load i8, ptr addrspace(1) %pa3, align 1
+ %xa3 = zext i8 %la3 to i32
+ %r3 = add nsw i32 %r2, %xa3
+ ret i32 %r3
+}
+
+define i32 @and8_zext_i8(ptr addrspace(1) %a) {
+; CHECK-LABEL: define i32 @and8_zext_i8(
+; CHECK-SAME: ptr addrspace(1) [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[A]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <8 x i8>, ptr addrspace(1) [[P0]], align 1
+; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.vector.reduce.and.v8i8(<8 x i8> [[TMP0]])
+; CHECK-NEXT: [[TMP2:%.*]] = zext i8 [[TMP1]] to i32
+; CHECK-NEXT: ret i32 [[TMP2]]
+;
+entry:
+ %p0 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 0
+ %l0 = load i8, ptr addrspace(1) %p0, align 1
+ %x0 = zext i8 %l0 to i32
+ %p1 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 1
+ %l1 = load i8, ptr addrspace(1) %p1, align 1
+ %x1 = zext i8 %l1 to i32
+ %p2 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 2
+ %l2 = load i8, ptr addrspace(1) %p2, align 1
+ %x2 = zext i8 %l2 to i32
+ %p3 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 3
+ %l3 = load i8, ptr addrspace(1) %p3, align 1
+ %x3 = zext i8 %l3 to i32
+ %p4 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 4
+ %l4 = load i8, ptr addrspace(1) %p4, align 1
+ %x4 = zext i8 %l4 to i32
+ %p5 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 5
+ %l5 = load i8, ptr addrspace(1) %p5, align 1
+ %x5 = zext i8 %l5 to i32
+ %p6 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 6
+ %l6 = load i8, ptr addrspace(1) %p6, align 1
+ %x6 = zext i8 %l6 to i32
+ %p7 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 7
+ %l7 = load i8, ptr addrspace(1) %p7, align 1
+ %x7 = zext i8 %l7 to i32
+ %r1 = and i32 %x0, %x1
+ %r2 = and i32 %r1, %x2
+ %r3 = and i32 %r2, %x3
+ %r4 = and i32 %r3, %x4
+ %r5 = and i32 %r4, %x5
+ %r6 = and i32 %r5, %x6
+ %r7 = and i32 %r6, %x7
+ ret i32 %r7
+}
+
+; The sum of four zero extended bytes inside a loop of 16 iterations. The load
+; saving is cancelled in every iteration, so the sum stays scalar there too.
+define void @sum4_zext_i8_loop(ptr addrspace(1) %a, ptr addrspace(1) %out) {
+; CHECK-LABEL: define void @sum4_zext_i8_loop(
+; CHECK-SAME: ptr addrspace(1) [[A:%.*]], ptr addrspace(1) [[OUT:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[OFF:%.*]] = shl i32 [[I]], 2
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[A]], i32 [[OFF]]
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i8>, ptr addrspace(1) [[PA0]], align 1
+; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i8> [[TMP0]] to <4 x i16>
+; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[TMP1]])
+; CHECK-NEXT: [[R3:%.*]] = zext i16 [[TMP2]] to i32
+; CHECK-NEXT: [[PO:%.*]] = getelementptr inbounds i32, ptr addrspace(1) [[OUT]], i32 [[I]]
+; CHECK-NEXT: store i32 [[R3]], ptr addrspace(1) [[PO]], align 4
+; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[I_NEXT]], 16
+; CHECK-NEXT: br i1 [[C]], label %[[LOOP]], label %[[EXIT:.*]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: ret void
+;
+entry:
+ br label %loop
+loop:
+ %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
+ %off = shl i32 %i, 2
+ %pa0 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 %off
+ %la0 = load i8, ptr addrspace(1) %pa0, align 1
+ %xa0 = zext i8 %la0 to i32
+ %pa1 = getelementptr inbounds i8, ptr addrspace(1) %pa0, i32 1
+ %la1 = load i8, ptr addrspace(1) %pa1, align 1
+ %xa1 = zext i8 %la1 to i32
+ %r1 = add nsw i32 %xa0, %xa1
+ %pa2 = getelementptr inbounds i8, ptr addrspace(1) %pa0, i32 2
+ %la2 = load i8, ptr addrspace(1) %pa2, align 1
+ %xa2 = zext i8 %la2 to i32
+ %r2 = add nsw i32 %r1, %xa2
+ %pa3 = getelementptr inbounds i8, ptr addrspace(1) %pa0, i32 3
+ %la3 = load i8, ptr addrspace(1) %pa3, align 1
+ %xa3 = zext i8 %la3 to i32
+ %r3 = add nsw i32 %r2, %xa3
+ %po = getelementptr inbounds i32, ptr addrspace(1) %out, i32 %i
+ store i32 %r3, ptr addrspace(1) %po, align 4
+ %i.next = add nuw nsw i32 %i, 1
+ %c = icmp ult i32 %i.next, 16
+ br i1 %c, label %loop, label %exit
+exit:
+ ret void
+}
+
+; The same sum over LDS with the first byte load aligned to four. The byte
+; loads coalesce into one dword load, so the sum stays scalar.
+define i32 @sum4_zext_i8_lds_a4(ptr addrspace(3) %a) {
+; CHECK-LABEL: define i32 @sum4_zext_i8_lds_a4(
+; CHECK-SAME: ptr addrspace(3) [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[A]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i8>, ptr addrspace(3) [[PA0]], align 4
+; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i8> [[TMP0]] to <4 x i16>
+; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[TMP1]])
+; CHECK-NEXT: [[R3:%.*]] = zext i16 [[TMP2]] to i32
+; CHECK-NEXT: ret i32 [[R3]]
+;
+entry:
+ %pa0 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 0
+ %la0 = load i8, ptr addrspace(3) %pa0, align 4
+ %xa0 = zext i8 %la0 to i32
+ %pa1 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 1
+ %la1 = load i8, ptr addrspace(3) %pa1, align 1
+ %xa1 = zext i8 %la1 to i32
+ %r1 = add nsw i32 %xa0, %xa1
+ %pa2 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 2
+ %la2 = load i8, ptr addrspace(3) %pa2, align 2
+ %xa2 = zext i8 %la2 to i32
+ %r2 = add nsw i32 %r1, %xa2
+ %pa3 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 3
+ %la3 = load i8, ptr addrspace(3) %pa3, align 1
+ %xa3 = zext i8 %la3 to i32
+ %r3 = add nsw i32 %r2, %xa3
+ ret i32 %r3
+}
+
+; The same sum over LDS with every byte load aligned to one byte. The backend
+; keeps these byte loads apart, so their load saving stays and the sum is
+; vectorized. The vector form reads the bytes through one misaligned dword
+; load and takes 14 or 15 instructions against 10 for the scalar form.
+define i32 @sum4_zext_i8_lds_a1(ptr addrspace(3) %a) {
+; CHECK-LABEL: define i32 @sum4_zext_i8_lds_a1(
+; CHECK-SAME: ptr addrspace(3) [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[A]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i8>, ptr addrspace(3) [[PA0]], align 1
+; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i8> [[TMP0]] to <4 x i16>
+; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[TMP1]])
+; CHECK-NEXT: [[TMP3:%.*]] = zext i16 [[TMP2]] to i32
+; CHECK-NEXT: ret i32 [[TMP3]]
+;
+entry:
+ %pa0 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 0
+ %la0 = load i8, ptr addrspace(3) %pa0, align 1
+ %xa0 = zext i8 %la0 to i32
+ %pa1 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 1
+ %la1 = load i8, ptr addrspace(3) %pa1, align 1
+ %xa1 = zext i8 %la1 to i32
+ %r1 = add nsw i32 %xa0, %xa1
+ %pa2 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 2
+ %la2 = load i8, ptr addrspace(3) %pa2, align 1
+ %xa2 = zext i8 %la2 to i32
+ %r2 = add nsw i32 %r1, %xa2
+ %pa3 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 3
+ %la3 = load i8, ptr addrspace(3) %pa3, align 1
+ %xa3 = zext i8 %la3 to i32
+ %r3 = add nsw i32 %r2, %xa3
+ ret i32 %r3
+}
+
+; The dot product of eight sign extended bytes over LDS with the first byte
+; load of each pointer aligned to 16. The byte loads coalesce into one load
+; per pointer, and a bundle of them is judged by the best alignment among
+; its loads, so a bundle starting at the second byte coalesces as well. The
+; dot product stays scalar. Vectorized on gfx90a it took 23 instructions
+; against 8 for the scalar form.
+define i32 @dot8_sext_i8_lds_a16(ptr addrspace(3) %a, ptr addrspace(3) %b) {
+; CHECK-LABEL: define i32 @dot8_sext_i8_lds_a16(
+; CHECK-SAME: ptr addrspace(3) [[A:%.*]], ptr addrspace(3) [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[A]], i32 0
+; CHECK-NEXT: [[PB0:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[B]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i8>, ptr addrspace(3) [[PA0]], align 16
+; CHECK-NEXT: [[TMP1:%.*]] = sext <4 x i8> [[TMP0]] to <4 x i32>
+; CHECK-NEXT: [[TMP2:%.*]] = load <4 x i8>, ptr addrspace(3) [[PB0]], align 16
+; CHECK-NEXT: [[TMP3:%.*]] = sext <4 x i8> [[TMP2]] to <4 x i32>
+; CHECK-NEXT: [[TMP4:%.*]] = mul nsw <4 x i32> [[TMP1]], [[TMP3]]
+; CHECK-NEXT: [[PA4:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[A]], i32 4
+; CHECK-NEXT: [[PB4:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[B]], i32 4
+; CHECK-NEXT: [[TMP5:%.*]] = load <4 x i8>, ptr addrspace(3) [[PA4]], align 4
+; CHECK-NEXT: [[TMP6:%.*]] = sext <4 x i8> [[TMP5]] to <4 x i32>
+; CHECK-NEXT: [[TMP7:%.*]] = load <4 x i8>, ptr addrspace(3) [[PB4]], align 4
+; CHECK-NEXT: [[TMP8:%.*]] = sext <4 x i8> [[TMP7]] to <4 x i32>
+; CHECK-NEXT: [[TMP9:%.*]] = mul nsw <4 x i32> [[TMP6]], [[TMP8]]
+; CHECK-NEXT: [[RDX_OP:%.*]] = add <4 x i32> [[TMP4]], [[TMP9]]
+; CHECK-NEXT: [[TMP10:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[RDX_OP]])
+; CHECK-NEXT: ret i32 [[TMP10]]
+;
+entry:
+ %pa0 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 0
+ %la0 = load i8, ptr addrspace(3) %pa0, align 16
+ %xa0 = sext i8 %la0 to i32
+ %pb0 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 0
+ %lb0 = load i8, ptr addrspace(3) %pb0, align 16
+ %xb0 = sext i8 %lb0 to i32
+ %m0 = mul nsw i32 %xa0, %xb0
+ %pa1 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 1
+ %la1 = load i8, ptr addrspace(3) %pa1, align 1
+ %xa1 = sext i8 %la1 to i32
+ %pb1 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 1
+ %lb1 = load i8, ptr addrspace(3) %pb1, align 1
+ %xb1 = sext i8 %lb1 to i32
+ %m1 = mul nsw i32 %xa1, %xb1
+ %r1 = add nsw i32 %m0, %m1
+ %pa2 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 2
+ %la2 = load i8, ptr addrspace(3) %pa2, align 2
+ %xa2 = sext i8 %la2 to i32
+ %pb2 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 2
+ %lb2 = load i8, ptr addrspace(3) %pb2, align 2
+ %xb2 = sext i8 %lb2 to i32
+ %m2 = mul nsw i32 %xa2, %xb2
+ %r2 = add nsw i32 %r1, %m2
+ %pa3 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 3
+ %la3 = load i8, ptr addrspace(3) %pa3, align 1
+ %xa3 = sext i8 %la3 to i32
+ %pb3 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 3
+ %lb3 = load i8, ptr addrspace(3) %pb3, align 1
+ %xb3 = sext i8 %lb3 to i32
+ %m3 = mul nsw i32 %xa3, %xb3
+ %r3 = add nsw i32 %r2, %m3
+ %pa4 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 4
+ %la4 = load i8, ptr addrspace(3) %pa4, align 4
+ %xa4 = sext i8 %la4 to i32
+ %pb4 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 4
+ %lb4 = load i8, ptr addrspace(3) %pb4, align 4
+ %xb4 = sext i8 %lb4 to i32
+ %m4 = mul nsw i32 %xa4, %xb4
+ %r4 = add nsw i32 %r3, %m4
+ %pa5 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 5
+ %la5 = load i8, ptr addrspace(3) %pa5, align 1
+ %xa5 = sext i8 %la5 to i32
+ %pb5 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 5
+ %lb5 = load i8, ptr addrspace(3) %pb5, align 1
+ %xb5 = sext i8 %lb5 to i32
+ %m5 = mul nsw i32 %xa5, %xb5
+ %r5 = add nsw i32 %r4, %m5
+ %pa6 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 6
+ %la6 = load i8, ptr addrspace(3) %pa6, align 2
+ %xa6 = sext i8 %la6 to i32
+ %pb6 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 6
+ %lb6 = load i8, ptr addrspace(3) %pb6, align 2
+ %xb6 = sext i8 %lb6 to i32
+ %m6 = mul nsw i32 %xa6, %xb6
+ %r6 = add nsw i32 %r5, %m6
+ %pa7 = getelementptr inbounds i8, ptr addrspace(3) %a, i32 7
+ %la7 = load i8, ptr addrspace(3) %pa7, align 1
+ %xa7 = sext i8 %la7 to i32
+ %pb7 = getelementptr inbounds i8, ptr addrspace(3) %b, i32 7
+ %lb7 = load i8, ptr addrspace(3) %pb7, align 1
+ %xb7 = sext i8 %lb7 to i32
+ %m7 = mul nsw i32 %xa7, %xb7
+ %r7 = add nsw i32 %r6, %m7
+ ret i32 %r7
+}
+
+; The sum of four sign extended bytes into i16 lanes. Two i16 lanes fit one
+; register, so the byte loads keep their saving and the sum stays vectorized.
+; On gfx1250 the scalar form takes 24 instructions against 18 for the vector
+; form.
+define i16 @sum4_sext_i8_i16(ptr addrspace(1) %a) {
+; CHECK-LABEL: define i16 @sum4_sext_i8_i16(
+; CHECK-SAME: ptr addrspace(1) [[A:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[A]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i8>, ptr addrspace(1) [[PA0]], align 1
+; CHECK-NEXT: [[TMP1:%.*]] = sext <4 x i8> [[TMP0]] to <4 x i16>
+; CHECK-NEXT: [[TMP2:%.*]] = call i16 @llvm.vector.reduce.add.v4i16(<4 x i16> [[TMP1]])
+; CHECK-NEXT: ret i16 [[TMP2]]
+;
+entry:
+ %pa0 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 0
+ %la0 = load i8, ptr addrspace(1) %pa0, align 1
+ %xa0 = sext i8 %la0 to i16
+ %pa1 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 1
+ %la1 = load i8, ptr addrspace(1) %pa1, align 1
+ %xa1 = sext i8 %la1 to i16
+ %r1 = add nsw i16 %xa0, %xa1
+ %pa2 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 2
+ %la2 = load i8, ptr addrspace(1) %pa2, align 1
+ %xa2 = sext i8 %la2 to i16
+ %r2 = add nsw i16 %r1, %xa2
+ %pa3 = getelementptr inbounds i8, ptr addrspace(1) %a, i32 3
+ %la3 = load i8, ptr addrspace(1) %pa3, align 1
+ %xa3 = sext i8 %la3 to i16
+ %r3 = add nsw i16 %r2, %xa3
+ ret i16 %r3
+}
+
+; The dot product of eight zero extended i16 loads. The i16 loads keep their
+; saving and the dot product stays vectorized. On gfx1250 the vector form
+; saves three VALU instructions, the gfx9 and gfx10 targets spend one more.
+define i32 @dot8_zext_i16(ptr addrspace(1) %a, ptr addrspace(1) %b) {
+; CHECK-LABEL: define i32 @dot8_zext_i16(
+; CHECK-SAME: ptr addrspace(1) [[A:%.*]], ptr addrspace(1) [[B:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[PA0:%.*]] = getelementptr inbounds i16, ptr addrspace(1) [[A]], i32 0
+; CHECK-NEXT: [[PB0:%.*]] = getelementptr inbounds i16, ptr addrspace(1) [[B]], i32 0
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x i16>, ptr addrspace(1) [[PA0]], align 2
+; CHECK-NEXT: [[TMP1:%.*]] = zext <4 x i16> [[TMP0]] to <4 x i32>
+; CHECK-NEXT: [[TMP2:%.*]] = load <4 x i16>, ptr addrspace(1) [[PB0]], align 2
+; CHECK-NEXT: [[TMP3:%.*]] = zext <4 x i16> [[TMP2]] to <4 x i32>
+; CHECK-NEXT: [[TMP4:%.*]] = mul nsw <4 x i32> [[TMP1]], [[TMP3]]
+; CHECK-NEXT: [[PA4:%.*]] = getelementptr inbounds i16, ptr addrspace(1) [[A]], i32 4
+; CHECK-NEXT: [[PB4:%.*]] = getelementptr inbounds i16, ptr addrspace(1) [[B]], i32 4
+; CHECK-NEXT: [[TMP5:%.*]] = load <4 x i16>, ptr addrspace(1) [[PA4]], align 2
+; CHECK-NEXT: [[TMP6:%.*]] = zext <4 x i16> [[TMP5]] to <4 x i32>
+; CHECK-NEXT: [[TMP7:%.*]] = load <4 x i16>, ptr addrspace(1) [[PB4]], align 2
+; CHECK-NEXT: [[TMP8:%.*]] = zext <4 x i16> [[TMP7]] to <4 x i32>
+; CHECK-NEXT: [[TMP9:%.*]] = mul nsw <4 x i32> [[TMP6]], [[TMP8]]
+; CHECK-NEXT: [[RDX_OP:%.*]] = add <4 x i32> [[TMP4]], [[TMP9]]
+; CHECK-NEXT: [[TMP10:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[RDX_OP]])
+; CHECK-NEXT: ret i32 [[TMP10]]
+;
+entry:
+ %pa0 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 0
+ %la0 = load i16, ptr addrspace(1) %pa0, align 2
+ %xa0 = zext i16 %la0 to i32
+ %pb0 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 0
+ %lb0 = load i16, ptr addrspace(1) %pb0, align 2
+ %xb0 = zext i16 %lb0 to i32
+ %m0 = mul nsw i32 %xa0, %xb0
+ %pa1 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 1
+ %la1 = load i16, ptr addrspace(1) %pa1, align 2
+ %xa1 = zext i16 %la1 to i32
+ %pb1 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 1
+ %lb1 = load i16, ptr addrspace(1) %pb1, align 2
+ %xb1 = zext i16 %lb1 to i32
+ %m1 = mul nsw i32 %xa1, %xb1
+ %r1 = add nsw i32 %m0, %m1
+ %pa2 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 2
+ %la2 = load i16, ptr addrspace(1) %pa2, align 2
+ %xa2 = zext i16 %la2 to i32
+ %pb2 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 2
+ %lb2 = load i16, ptr addrspace(1) %pb2, align 2
+ %xb2 = zext i16 %lb2 to i32
+ %m2 = mul nsw i32 %xa2, %xb2
+ %r2 = add nsw i32 %r1, %m2
+ %pa3 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 3
+ %la3 = load i16, ptr addrspace(1) %pa3, align 2
+ %xa3 = zext i16 %la3 to i32
+ %pb3 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 3
+ %lb3 = load i16, ptr addrspace(1) %pb3, align 2
+ %xb3 = zext i16 %lb3 to i32
+ %m3 = mul nsw i32 %xa3, %xb3
+ %r3 = add nsw i32 %r2, %m3
+ %pa4 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 4
+ %la4 = load i16, ptr addrspace(1) %pa4, align 2
+ %xa4 = zext i16 %la4 to i32
+ %pb4 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 4
+ %lb4 = load i16, ptr addrspace(1) %pb4, align 2
+ %xb4 = zext i16 %lb4 to i32
+ %m4 = mul nsw i32 %xa4, %xb4
+ %r4 = add nsw i32 %r3, %m4
+ %pa5 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 5
+ %la5 = load i16, ptr addrspace(1) %pa5, align 2
+ %xa5 = zext i16 %la5 to i32
+ %pb5 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 5
+ %lb5 = load i16, ptr addrspace(1) %pb5, align 2
+ %xb5 = zext i16 %lb5 to i32
+ %m5 = mul nsw i32 %xa5, %xb5
+ %r5 = add nsw i32 %r4, %m5
+ %pa6 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 6
+ %la6 = load i16, ptr addrspace(1) %pa6, align 2
+ %xa6 = zext i16 %la6 to i32
+ %pb6 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 6
+ %lb6 = load i16, ptr addrspace(1) %pb6, align 2
+ %xb6 = zext i16 %lb6 to i32
+ %m6 = mul nsw i32 %xa6, %xb6
+ %r6 = add nsw i32 %r5, %m6
+ %pa7 = getelementptr inbounds i16, ptr addrspace(1) %a, i32 7
+ %la7 = load i16, ptr addrspace(1) %pa7, align 2
+ %xa7 = zext i16 %la7 to i32
+ %pb7 = getelementptr inbounds i16, ptr addrspace(1) %b, i32 7
+ %lb7 = load i16, ptr addrspace(1) %pb7, align 2
+ %xb7 = zext i16 %lb7 to i32
+ %m7 = mul nsw i32 %xa7, %xb7
+ %r7 = add nsw i32 %r6, %m7
+ ret i32 %r7
+}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; GFX1030: {{.*}}
----------------
MrSidims wrote:
Cleared
https://github.com/llvm/llvm-project/pull/228901
More information about the llvm-commits
mailing list