]> git.ipfire.org Git - thirdparty/gcc.git/commit
match.pd: Fold pattern of round semantics.
authorzhaozhou <zhaozhou@loongson.cn>
Thu, 23 Oct 2025 10:52:22 +0000 (18:52 +0800)
committerRichard Biener <rguenth@gcc.gnu.org>
Thu, 23 Oct 2025 11:50:45 +0000 (13:50 +0200)
commitfe9f0719d8ebd2bb3e6e1ecd3b3167931d42dabd
treec6f04a486c351487a97a60718f8875aa23905f9a
parent9e5a9aa49051c3d60f6d0071c0711b2202902479
match.pd: Fold pattern of round semantics.

In the 538.imagick_r benchmark of Spec2017, I find these pattern from
MagickRound function. This patch implements these pattern in match.pd
for 4 rules:
1) (x-floor(x)) < (ceil(x)-x) ? floor(x) : ceil(x) -> floor(x+0.5)
2) (x-floor(x)) >= (ceil(x)-x) ? ceil(x) : floor(x) -> floor(x+0.5)
3) (ceil(x)-x) > (x-floor(x)) ? floor(x) : ceil(x) -> floor(x+0.5)
4) (ceil(x)-x) <= (x-floor(x)) ? ceil(x) : floor(x) -> floor(x+0.5)

The patch implements floor(x+0.5) operation to replace these pattern
that semantics of round(x) function.

The patch was regtested on aarch64-linux-gnu and x86_64-linux-gnu,
SPEC 2017 and SPEC 2006 were run:
As for SPEC 2017, 538.imagick_r benchmark performance increased by 3%+
in base test of ratio mode.
As for SPEC 2006, while the transform does not seem to be triggered,
we also see no non-noise impact on performance.

gcc/ChangeLog:

* match.pd: Add new pattern for round.

gcc/testsuite/ChangeLog:

* gcc.dg/fold-round-1.c: New test.
gcc/match.pd
gcc/testsuite/gcc.dg/fold-round-1.c [new file with mode: 0644]