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

inefficient floating point register ld/st instructions are generated when -mcpu=power8 is specified

Open weiguozhi opened this issue 11 years ago • 7 comments

Bugzilla Link 24817
Version trunk
OS Linux
CC @hfinkel,@nemanjai

Extended Description

The simple test case is:

int foo(float *p) { float f1 = p[1]; float f2 = p[2]; return f1 > f2; }

Compiler command line and output

clang -S t8.c --target=powerpc -m64 -mcpu=power8 -O2 li 4, 4 // A li 5, 8 // B lxsspx 0, 3, 4 // C lxsspx 1, 3, 5 // D li 3, 0 li 4, 1 fcmpu 0, 0, 1 isel 3, 4, 3, 1 blr

If I change -mcpu=power8 to -mcpu=power7, I got

lfs 0, 4(3)        // E
lfs 1, 8(3)        // F
li 3, 0
li 4, 1
fcmpu 0, 0, 1
isel 3, 4, 3, 1
blr

Instructions AC are replaced by E Instructions BD are replaced by F

weiguozhi avatar Sep 15 '15 00:09 weiguozhi

It's OK to me.

weiguozhi avatar May 24 '17 16:05 weiguozhi

Carrot, are you OK with closing this PR as a limitation on P8?

llvmbot avatar May 24 '17 03:05 llvmbot

Since Power9 has scalar D-Form loads and stores that can operate on the full VSX register set, this is not an issue on Power9. The code produced for this on Power9 is the same as the code on Power7. I think that given the limitation of Power8 in terms of not having D-Form loads for all the VSX registers along with the intent to favour VSX due to the larger register set, we should leave the Power8 code as is and close this PR. Please let me know what you think.

nemanjai avatar Oct 31 '16 14:10 nemanjai

The reason this happens is that we have the AddedComplexity set on VSX instructions to favour them and the VSX indexed loads/stores are defined within that block. Of course, the exact same thing happens with double precision values. However, this isn't P8 specific since we've had indexed double precision VSX loads in P7 as well.

The easy solution for this problem is to extract the VSX indexed loads from the AddedComplexity block. However, we will then never load such values in the upper VSX registers.

It might be better to peephole this after register allocation. You want the larger register classes to be available during RA for high-register-pressure situations. If that turns out to be unnecessary, we could relax after the fact. This approach is not exactly optimal, but seems better than the other relatively-easy alternatives.

hfinkel avatar Feb 10 '16 15:02 hfinkel

The reason this happens is that we have the AddedComplexity set on VSX instructions to favour them and the VSX indexed loads/stores are defined within that block. Of course, the exact same thing happens with double precision values. However, this isn't P8 specific since we've had indexed double precision VSX loads in P7 as well.

The easy solution for this problem is to extract the VSX indexed loads from the AddedComplexity block. However, we will then never load such values in the upper VSX registers.

nemanjai avatar Feb 10 '16 15:02 nemanjai

assigned to @nemanjai

weiguozhi avatar Sep 15 '15 00:09 weiguozhi

https://godbolt.org/z/jY3oscPef

Trunk is good even for Pwr8

chenzheng1030 avatar Jan 07 '24 03:01 chenzheng1030