RISC-V: Align IOR optimization MODE_CLASS condition to AND.
commit978e8f02e8edebaf21ce32768cce603f650459e4
authorPan Li <pan2.li@intel.com>
Wed, 19 Apr 2023 09:18:20 +0000 (19 17:18 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Wed, 19 Apr 2023 15:16:29 +0000 (19 23:16 +0800)
treeec1d88bc2358ad36a4879ded00d5c99d1372b890
parent0df6d181230f0480547ed08b4e4354db68242724
RISC-V: Align IOR optimization MODE_CLASS condition to AND.

This patch aligned the MODE_CLASS condition of the IOR to the AND. Then
more MODE_CLASS besides SCALAR_INT can able to perform the optimization
A | (~A) -> -1 similar to AND operator. For example as below sample code.

vbool32_t test_shortcut_for_riscv_vmorn_case_5(vbool32_t v1, size_t vl)
{
  return __riscv_vmorn_mm_b32(v1, v1, vl);
}

Before this patch:
vsetvli  a5,zero,e8,mf4,ta,ma
vlm.v    v24,0(a1)
vsetvli  zero,a2,e8,mf4,ta,ma
vmorn.mm v24,v24,v24
vsetvli  a5,zero,e8,mf4,ta,ma
vsm.v    v24,0(a0)
ret

After this patch:
vsetvli zero,a2,e8,mf4,ta,ma
vmset.m v24
vsetvli a5,zero,e8,mf4,ta,ma
vsm.v   v24,0(a0)
ret

Or in RTL's perspective,
from:
(ior:VNx2BI (reg/v:VNx2BI 137 [ v1 ]) (not:VNx2BI (reg/v:VNx2BI 137 [ v1 ])))
to:
(const_vector:VNx2BI repeat [ (const_int 1 [0x1]) ])

The similar optimization like VMANDN has enabled already. There should
be no difference execpt the operator when compare the VMORN and VMANDN
for such kind of optimization. The patch aligns the IOR MODE_CLASS condition
of the simplification to the AND operator.

gcc/ChangeLog:

* simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
Align IOR (A | (~A) -> -1) optimization MODE_CLASS condition to AND.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/rvv/base/mask_insn_shortcut.c: Update check
condition.
* gcc.target/riscv/simplify_ior_optimization.c: New test.

Signed-off-by: Pan Li <pan2.li@intel.com>
gcc/simplify-rtx.cc
gcc/testsuite/gcc.target/riscv/rvv/base/mask_insn_shortcut.c
gcc/testsuite/gcc.target/riscv/simplify_ior_optimization.c [new file with mode: 0644]