diff options
author | xuli <xuli1@eswincomputing.com> | 2024-10-22 09:48:03 +0000 |
---|---|---|
committer | xuli <xuli1@eswincomputing.com> | 2024-10-30 00:57:22 +0000 |
commit | 4af8db3eca12b2db3753ce4b098cbd0ae32b4796 (patch) | |
tree | ac755bd3df41e5ebd3b606491bb0cc6a375d8e9c /gcc/function.cc | |
parent | 17643e5a6808f4a7161a7aa9234a4999b74f6b1a (diff) | |
download | gcc-4af8db3eca12b2db3753ce4b098cbd0ae32b4796.zip gcc-4af8db3eca12b2db3753ce4b098cbd0ae32b4796.tar.gz gcc-4af8db3eca12b2db3753ce4b098cbd0ae32b4796.tar.bz2 |
Match: Simplify (x != 0 ? x + ~0 : 0) to (x - x != 0).
When the imm operand op1=1 in the unsigned scalar sat_sub form2 below,
we can simplify (x != 0 ? x + ~0 : 0) to (x - x != 0), thereby eliminating
a branch instruction.This simplification also applies to signed integer.
Form2:
T __attribute__((noinline)) \
sat_u_sub_imm##IMM##_##T##_fmt_2 (T x) \
{ \
return x >= (T)IMM ? x - (T)IMM : 0; \
}
Take below form 2 as example:
DEF_SAT_U_SUB_IMM_FMT_2(uint8_t, 1)
Before this patch:
__attribute__((noinline))
uint8_t sat_u_sub_imm1_uint8_t_fmt_2 (uint8_t x)
{
uint8_t _1;
uint8_t _3;
<bb 2> [local count: 1073741824]:
if (x_2(D) != 0)
goto <bb 3>; [50.00%]
else
goto <bb 4>; [50.00%]
<bb 3> [local count: 536870912]:
_3 = x_2(D) + 255;
<bb 4> [local count: 1073741824]:
# _1 = PHI <x_2(D)(2), _3(3)>
return _1;
}
Assembly code:
sat_u_sub_imm1_uint8_t_fmt_2:
beq a0,zero,.L2
addiw a0,a0,-1
andi a0,a0,0xff
.L2:
ret
After this patch:
__attribute__((noinline))
uint8_t sat_u_sub_imm1_uint8_t_fmt_2 (uint8_t x)
{
_Bool _1;
unsigned char _2;
uint8_t _4;
<bb 2> [local count: 1073741824]:
_1 = x_3(D) != 0;
_2 = (unsigned char) _1;
_4 = x_3(D) - _2;
return _4;
}
Assembly code:
sat_u_sub_imm1_uint8_t_fmt_2:
snez a5,a0
subw a0,a0,a5
andi a0,a0,0xff
ret
The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.
Signed-off-by: Li Xu <xuli1@eswincomputing.com>
gcc/ChangeLog:
* match.pd: Simplify (x != 0 ? x + ~0 : 0) to (x - x != 0).
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/phi-opt-44.c: New test.
* gcc.dg/tree-ssa/phi-opt-45.c: New test.
Diffstat (limited to 'gcc/function.cc')
0 files changed, 0 insertions, 0 deletions