]> git.ipfire.org Git - thirdparty/gcc.git/commit
match: Fix some `(op (cnd @0 @1 @2) @3)` patterns [PR123778]
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 23 Jan 2026 07:12:42 +0000 (23:12 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 23 Jan 2026 19:17:01 +0000 (11:17 -0800)
commit0cdcc61fb9976b9f6ba2fbf5e9211c3e23a9799c
tree6cbd0d189e3834ddf46e38a6cc9814c3d6d90d00
parentc01ad7a27af18f430639b6ec9597199eb655cc76
match: Fix some `(op (cnd @0 @1 @2) @3)` patterns [PR123778]

All of these patterns have in common is they try to move
the op inside the cnd if it simplifies. The problem is the
type of the op does not need to be the type of first operand
and instead is the type of the type variable. The fix is to
supply the type to the op like in `(op:type @1 @3)`.
But since they were originally in the `(op! @1 @3)`, it should be:
`(op!:type @1 @3)`. Though this would be rejected as we don't pick
up the next token after parsing the `!` (note `^` has the same issue
which is also fixed here too).

Bootstrapped and tested on x86_64-linux-gnu.

PR tree-optimization/123778

gcc/ChangeLog:

* genmatch.cc (parser::parse_expr): Peek on the next
token after eating the `!` or `^`.
* match.pd (`(op (cnd @0 @1 @2) @3)`, `(op @3 (cnd @0 @1 @2))`):
Add the type to resulting op.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr123778-1.c: New test.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/genmatch.cc
gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr123778-1.c [new file with mode: 0644]