diff options
author | Pan Li <pan2.li@intel.com> | 2024-10-24 21:57:04 +0800 |
---|---|---|
committer | Pan Li <pan2.li@intel.com> | 2024-10-25 21:52:43 +0800 |
commit | df4af89bc3eabbeaccb16539aa1082cb9863e187 (patch) | |
tree | 09ec974a2f102735fc3cb6f5c13b84b1f6c8fa3e /gcc/fortran/trans-expr.cc | |
parent | e2a8772c9328960c625f5b95091d4312efa0e284 (diff) | |
download | gcc-df4af89bc3eabbeaccb16539aa1082cb9863e187.zip gcc-df4af89bc3eabbeaccb16539aa1082cb9863e187.tar.gz gcc-df4af89bc3eabbeaccb16539aa1082cb9863e187.tar.bz2 |
Match: Simplify branch form 3 of unsigned SAT_ADD into branchless
There are sorts of forms for the unsigned SAT_ADD. Some of them are
complicated while others are cheap. This patch would like to simplify
the complicated form into the cheap ones. For example as below:
From the form 3 (branch):
SAT_U_ADD = (X + Y) >= x ? (X + Y) : -1.
To (branchless):
SAT_U_ADD = (X + Y) | - ((X + Y) < X).
#define T uint8_t
T sat_add_u_1 (T x, T y)
{
return (T)(x + y) >= x ? (x + y) : -1;
}
Before this patch:
1 │ uint8_t sat_add_u_1 (uint8_t x, uint8_t y)
2 │ {
3 │ uint8_t D.2809;
4 │
5 │ _1 = x + y;
6 │ if (x <= _1) goto <D.2810>; else goto <D.2811>;
7 │ <D.2810>:
8 │ D.2809 = x + y;
9 │ goto <D.2812>;
10 │ <D.2811>:
11 │ D.2809 = 255;
12 │ <D.2812>:
13 │ return D.2809;
14 │ }
After this patch:
1 │ uint8_t sat_add_u_1 (uint8_t x, uint8_t y)
2 │ {
3 │ uint8_t D.2809;
4 │
5 │ _1 = x + y;
6 │ _2 = x + y;
7 │ _3 = x > _2;
8 │ _4 = (unsigned char) _3;
9 │ _5 = -_4;
10 │ D.2809 = _1 | _5;
11 │ return D.2809;
12 │ }
The simplify doesn't need to check if target support the SAT_ADD, it
is somehow the optimization in gimple level.
The below test suites are passed for this patch.
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 fully regression test.
gcc/ChangeLog:
* match.pd: Remove unsigned branch form 3 for SAT_ADD, and
add simplify to branchless instead.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/sat_u_add-simplify-1-u16.c: New test.
* gcc.dg/tree-ssa/sat_u_add-simplify-1-u32.c: New test.
* gcc.dg/tree-ssa/sat_u_add-simplify-1-u64.c: New test.
* gcc.dg/tree-ssa/sat_u_add-simplify-1-u8.c: New test.
Signed-off-by: Pan Li <pan2.li@intel.com>
Diffstat (limited to 'gcc/fortran/trans-expr.cc')
0 files changed, 0 insertions, 0 deletions