[llvm] [NVPTX] Fix the error in a pattern match in v4i8 comparisons. (PR #81308)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 9 11:51:08 PST 2024
================
@@ -251,31 +251,39 @@ define <4 x i8> @test_smax(<4 x i8> %a, <4 x i8> %b) #0 {
; CHECK-LABEL: test_smax(
; CHECK: {
; CHECK-NEXT: .reg .pred %p<5>;
-; CHECK-NEXT: .reg .b32 %r<19>;
+; CHECK-NEXT: .reg .b32 %r<27>;
; CHECK-EMPTY:
; CHECK-NEXT: // %bb.0:
; CHECK-NEXT: ld.param.u32 %r2, [test_smax_param_1];
; CHECK-NEXT: ld.param.u32 %r1, [test_smax_param_0];
-; CHECK-NEXT: bfe.s32 %r3, %r1, 24, 8;
-; CHECK-NEXT: bfe.s32 %r4, %r2, 24, 8;
-; CHECK-NEXT: setp.gt.s32 %p1, %r3, %r4;
-; CHECK-NEXT: bfe.s32 %r5, %r1, 16, 8;
-; CHECK-NEXT: bfe.s32 %r6, %r2, 16, 8;
-; CHECK-NEXT: setp.gt.s32 %p2, %r5, %r6;
-; CHECK-NEXT: bfe.s32 %r7, %r1, 8, 8;
-; CHECK-NEXT: bfe.s32 %r8, %r2, 8, 8;
-; CHECK-NEXT: setp.gt.s32 %p3, %r7, %r8;
-; CHECK-NEXT: bfe.s32 %r9, %r1, 0, 8;
-; CHECK-NEXT: bfe.s32 %r10, %r2, 0, 8;
-; CHECK-NEXT: setp.gt.s32 %p4, %r9, %r10;
-; CHECK-NEXT: selp.b32 %r11, %r9, %r10, %p4;
-; CHECK-NEXT: selp.b32 %r12, %r7, %r8, %p3;
-; CHECK-NEXT: bfi.b32 %r13, %r12, %r11, 8, 8;
-; CHECK-NEXT: selp.b32 %r14, %r5, %r6, %p2;
-; CHECK-NEXT: bfi.b32 %r15, %r14, %r13, 16, 8;
-; CHECK-NEXT: selp.b32 %r16, %r3, %r4, %p1;
-; CHECK-NEXT: bfi.b32 %r17, %r16, %r15, 24, 8;
-; CHECK-NEXT: st.param.b32 [func_retval0+0], %r17;
+; CHECK-NEXT: bfe.s32 %r3, %r2, 24, 8;
+; CHECK-NEXT: bfe.s32 %r4, %r1, 24, 8;
+; CHECK-NEXT: setp.gt.s32 %p1, %r4, %r3;
+; CHECK-NEXT: bfe.s32 %r5, %r2, 16, 8;
+; CHECK-NEXT: bfe.s32 %r6, %r1, 16, 8;
+; CHECK-NEXT: setp.gt.s32 %p2, %r6, %r5;
+; CHECK-NEXT: bfe.s32 %r7, %r2, 8, 8;
+; CHECK-NEXT: bfe.s32 %r8, %r1, 8, 8;
+; CHECK-NEXT: setp.gt.s32 %p3, %r8, %r7;
+; CHECK-NEXT: bfe.s32 %r9, %r2, 0, 8;
+; CHECK-NEXT: bfe.s32 %r10, %r1, 0, 8;
+; CHECK-NEXT: setp.gt.s32 %p4, %r10, %r9;
+; CHECK-NEXT: bfe.u32 %r11, %r1, 24, 8;
+; CHECK-NEXT: bfe.u32 %r12, %r1, 16, 8;
+; CHECK-NEXT: bfe.u32 %r13, %r1, 8, 8;
+; CHECK-NEXT: bfe.u32 %r14, %r1, 0, 8;
+; CHECK-NEXT: bfe.u32 %r15, %r2, 0, 8;
+; CHECK-NEXT: selp.b32 %r16, %r14, %r15, %p4;
+; CHECK-NEXT: bfe.u32 %r17, %r2, 8, 8;
+; CHECK-NEXT: selp.b32 %r18, %r13, %r17, %p3;
+; CHECK-NEXT: bfi.b32 %r19, %r18, %r16, 8, 8;
+; CHECK-NEXT: bfe.u32 %r20, %r2, 16, 8;
----------------
Artem-B wrote:
These additional BFE instructions are a side effect of the signed difference of BFE we use during lowering of `extractelement`. The pattern-matched comparison folds extract/trunc/sext into a signed BFE, while loading/storing of the elements uses just extractelement value which is lowered as BFE.u32. While PTX is more verbose, ptxas appears to do a reasonably good job here. For sm_80 the difference on the SASS level is that the old code used USEL (select), while the new one uses predicated `PRMT`. The number of instructions is about the same.
https://github.com/llvm/llvm-project/pull/81308
More information about the llvm-commits
mailing list