diff options
author | Lulu Cheng <chenglulu@loongson.cn> | 2023-08-24 16:44:56 +0800 |
---|---|---|
committer | Lulu Cheng <chenglulu@loongson.cn> | 2023-08-28 10:33:19 +0800 |
commit | c28c579f0dd9cd27f90df9aff7cbdb2db1c23b3b (patch) | |
tree | 174505f4d7a9b807aebadd3b7a14f368bbeaab0f /gcc/tree-ssa-phiopt.cc | |
parent | 1671ad9ecff9f361870aeb26d5c5c6d9808826d7 (diff) | |
download | gcc-c28c579f0dd9cd27f90df9aff7cbdb2db1c23b3b.zip gcc-c28c579f0dd9cd27f90df9aff7cbdb2db1c23b3b.tar.gz gcc-c28c579f0dd9cd27f90df9aff7cbdb2db1c23b3b.tar.bz2 |
LoongArch: Remove redundant sign extension instructions caused by SLT instructions.
Since the SLT instruction does not distinguish between 64-bit operations and 32-bit
operations under the 64-bit LoongArch architecture, if the operand of slt is SImode,
the sign extension of the operand needs to be displayed.
But similar to the test case below, the sign extension is redundant:
extern int src1, src2, src3;
int
test (void)
{
int data1 = src1 + src2;
int data2 = src1 + src3;
return data1 > data2 ? data1 : data2;
}
Assembly code before optimization:
...
add.w $r4,$r4,$r14
add.w $r13,$r13,$r14
slli.w $r12,$r4,0
slli.w $r14,$r13,0
slt $r12,$r12,$r14
masknez $r4,$r4,$r12
maskeqz $r12,$r13,$r12
or $r4,$r4,$r12
slli.w $r4,$r4,0
...
After optimization:
...
add.w $r12,$r12,$r14
add.w $r13,$r13,$r14
slt $r4,$r12,$r13
masknez $r12,$r12,$r4
maskeqz $r4,$r13,$r4
or $r4,$r12,$r4
...
Similar to this test example, the two operands of SLT are obtained by the
addition operation, and add.w implicitly sign-extends, so the two operands
of SLT do not require sign-extend.
gcc/ChangeLog:
* config/loongarch/loongarch.cc (loongarch_expand_conditional_move):
Optimize the function implementation.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/slt-sign-extend.c: New test.
Diffstat (limited to 'gcc/tree-ssa-phiopt.cc')
0 files changed, 0 insertions, 0 deletions