]> git.ipfire.org Git - thirdparty/gcc.git/commit
[RISC-V][PR target/116240] Ensure object is a comparison before extracting arguments
authorJeff Law <jlaw@ventanamicro.com>
Thu, 8 Aug 2024 13:42:26 +0000 (07:42 -0600)
committerKito Cheng <kito.cheng@sifive.com>
Wed, 9 Apr 2025 14:03:12 +0000 (22:03 +0800)
commit86b0f63adb0815b407050514333384dcb7ac640d
treed792834c7b9218bb02929cd49073f336ef261f7a
parent28fe2b087baea05759aa7386fb8c3862aecf51ef
[RISC-V][PR target/116240] Ensure object is a comparison before extracting arguments

This was supposed to go out the door yesterday, but I kept getting interrupted.

The target bits for rtx costing can't assume the rtl they're given actually
matches a target pattern.   It's just kind of inherent in how the costing
routines get called in various places.

In this particular case we're trying to cost a conditional move:

(set (dest) (if_then_else (cond) (true) (false))

On the RISC-V port the backend only allows actual conditionals for COND.  So
something like (eq (reg) (const_int 0)).  In the costing code for if-then-else
we did something like

(XEXP (XEXP (cond, 0), 0)))

Which fails miserably if COND is a terminal node like (reg) rather than (ne
(reg) (const_int 0)

So this patch tightens up the RTL scanning to ensure that we have a comparison
before we start looking at the comparison's arguments.

Run through my tester without incident, but I'll wait for the pre-commit tester
to run through a cycle before pushing to the trunk.

Jeff

ps.   We probably could support a naked REG for the condition and internally convert it to (ne (reg) (const_int 0)), but I don't think it likely happens with any regularity.

PR target/116240
gcc/
* config/riscv/riscv.cc (riscv_rtx_costs): Ensure object is a
comparison before looking at its arguments.

gcc/testsuite
* gcc.target/riscv/pr116240.c: New test.
gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/pr116240.c [new file with mode: 0644]