On 11/22/23 10:47 PM, Feng Wang wrote:
This patch add another condition for gimple-cond optimization. Refer to
the following test case.
int foo1 (int data, int res)
{
res = data & 0xf;
res |= res << 4;
if (res < 0x22)
return 0x22;
return res;
}
with the compilation flag "-march=rv64gc_zba_zbb -mabi=lp64d -O2",
before this patch the compilation result is
foo1:
andi a0,a0,15
slliw a5,a0,4
addw a3,a5,a0
li a4,33
add a0,a5,a0
bleu a3,a4,.L5
ret
.L5:
li a0,34
ret
after this patch the compilation result is
foo1:
andi a0,a0,15
slliw a5,a0,4
add a5,a5,a0
li a0,34
max a0,a5,a0
ret
The reason is in the pass_early_vrp, the arg0 of gimple_cond
is replaced,but the PHI node still use the arg0.
The some of evrp pass logs are as follows
gimple_assign <mult_expr, _9, _7, 17, NULL>
gimple_assign <nop_expr, res_5, _9, NULL, NULL>
gimple_cond <le_expr, _9, 33, NULL, NULL>
goto <bb 3>; [INV]
else
goto <bb 4>; [INV]
<bb 3> :
// predicted unlikely by early return (on trees) predictor.
<bb 4> :
# gimple_phi <_2, 34(3), res_5(2)>
The arg0 of gimple_cond is replaced by _9,but the gimple_phi still
uses res_5,it will cause optimization fail of PHI node to MAX_EXPR.
So the next_use_is_phi is added to control the replacement.
gcc/ChangeLog:
* vr-values.cc (next_use_is_phi):
(simplify_using_ranges::simplify_casted_compare):
add new function next_use_is_phi to control the replacement.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/zbb-min-max-04.c: New test.
I'm not sure what changed, but AFAICT this patch isn't needed anymore.
We get the desired code with the trunk compiler.
Jeff