]> git.ipfire.org Git - thirdparty/gcc.git/commit
expand: Split divisions with near-power-of-two divisors [PR middle-end/125708] master trunk
authorliuhongt <hongtao.liu@intel.com>
Fri, 12 Jun 2026 08:43:32 +0000 (01:43 -0700)
committerliuhongt <hongtao.liu@intel.com>
Wed, 5 Aug 2026 02:01:45 +0000 (19:01 -0700)
commit298071eb7e88b01adc6a88f9eba797edaedec170
treed26b2e25f28f1cb8bd724b9c02dfd7ea91402e4d
parent8f60387387e6c08071abe1493db849c459492e3e
expand: Split divisions with near-power-of-two divisors [PR middle-end/125708]

When range info proves that a TRUNC_DIV_EXPR divisor is either N or N
+ 1, and one value is a positive power of two, expand the operation as
two constant divisions selected by a conditional move.

Only do this for speed, when conditional moves are available.  Cost
the split sequence against a plain DIV/UDIV and keep the original
expansion unless the split is cheaper.

PR middle-end/125708

gcc/ChangeLog:

* expr.cc: Include gimple-range.h.
(near_pow2_divisor_range_p): New function.
(expand_expr_divmod): Split eligible TRUNC_DIV_EXPRs into two
constant divisions selected by a conditional move.

gcc/testsuite/ChangeLog:

* gcc.dg/torture/pr125708-1.c: New test.
* gcc.target/i386/pr125708-2.c: New test.
gcc/expr.cc
gcc/testsuite/gcc.dg/torture/pr125708-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr125708-2.c [new file with mode: 0644]