llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[PowerPC] xxspltib can not hoist out of loop.

Open diggerlin opened this issue 1 year ago • 1 comments

bash> cat tc.cpp

#include <altivec.h> void foo (float* __restrict _a,float* __restrict In_a,int* __restrict n) { for(int j=0;j<*n;j++) { vector float v21; vector unsigned char v36; vector unsigned char v37; vector unsigned char v39; v36=(vector unsigned char) {2,2,2,2,6,6,6,6,1,1,1,1,4,4,4,4}; v37=(vector unsigned char) {6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6}; v21=vec_promote(In_a[j],0); v39=vec_sel((vector unsigned char)v36, (vector unsigned char)v21, (vector unsigned char)v37); _a[j] = vec_extract((vector float)v39,0); } }

bash>clang -o tc.s -S tc.cpp -O3 -maltivec -mcpu=pwr10 -m64

cat> tc.s

# %bb.2:                                # %for.body.preheader.new
        rlwinm r6, r5, 0, 1, 30
        addi r10, r4, -8
        addi r7, r3, -8
        li r8, 8
        li r9, 12
        li r11, 4
        addi r6, r6, -2
        rldicl r6, r6, 63, 1
        addi r6, r6, 1
        mtctr r6
        li r6, 0
        .align  4
L..BB0_3:                               # %for.body
                                        # =>This Inner Loop Header: Depth=1
        lxvwsx vs0, r10, r8
        xxspltib vs1, 6
        addi r6, r6, 2
        xxland vs0, vs0, vs1
        xscvspdpn f0, vs0
        stfsu f0, 8(r7)
        lxvwsx vs0, r10, r9
        addi r10, r10, 8
        xxland vs0, vs0, vs1
        xxsldwi vs0, vs0, vs0, 3
        stfiwx f0, r7, r11
        bdnz L..BB0_3

the instruction xxspltib vs1, 6 in the block L..BB0_3 should be hoist out the loop L..BB0_3 to make the code more efficient.

diggerlin avatar Feb 13 '25 20:02 diggerlin

@llvm/issue-subscribers-backend-powerpc

Author: zhijian lin (diggerlin)

bash> cat tc.cpp

#include <altivec.h> void foo (float* __restrict _a,float* __restrict In_a,int* __restrict n) { for(int j=0;j<*n;j++) { vector float v21; vector unsigned char v36; vector unsigned char v37; vector unsigned char v39; v36=(vector unsigned char) {2,2,2,2,6,6,6,6,1,1,1,1,4,4,4,4}; v37=(vector unsigned char) {6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6}; v21=vec_promote(In_a[j],0); v39=vec_sel((vector unsigned char)v36, (vector unsigned char)v21, (vector unsigned char)v37); _a[j] = vec_extract((vector float)v39,0); } }

bash>clang -o tc.s -S tc.cpp -O3 -maltivec -mcpu=pwr10 -m64

cat> tc.s

# %bb.2:                                # %for.body.preheader.new
        rlwinm r6, r5, 0, 1, 30
        addi r10, r4, -8
        addi r7, r3, -8
        li r8, 8
        li r9, 12
        li r11, 4
        addi r6, r6, -2
        rldicl r6, r6, 63, 1
        addi r6, r6, 1
        mtctr r6
        li r6, 0
        .align  4
L..BB0_3:                               # %for.body
                                        # =&gt;This Inner Loop Header: Depth=1
        lxvwsx vs0, r10, r8
        xxspltib vs1, 6
        addi r6, r6, 2
        xxland vs0, vs0, vs1
        xscvspdpn f0, vs0
        stfsu f0, 8(r7)
        lxvwsx vs0, r10, r9
        addi r10, r10, 8
        xxland vs0, vs0, vs1
        xxsldwi vs0, vs0, vs0, 3
        stfiwx f0, r7, r11
        bdnz L..BB0_3

the instruction xxspltib vs1, 6 in the block L..BB0_3 should be hoist out the loop L..BB0_3

llvmbot avatar Feb 13 '25 20:02 llvmbot