Bug 33258 - guaranteed-true arithmetic test not optimized away depending on constant
Summary: guaranteed-true arithmetic test not optimized away depending on constant
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 10.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2007-08-31 07:52 UTC by Ken Raeburn
Modified: 2021-08-08 17:42 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
C test case, description and assembly in comments (737 bytes, text/plain)
2007-08-31 07:53 UTC, Ken Raeburn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ken Raeburn 2007-08-31 07:52:28 UTC
As in 33257, I was playing around with division+remainder code, and found another case gcc didn't optimize.  I was using signed and unsigned variants, and tried a couple different constants.  The test case was optimized properly with the constant 3 (signed or unsigned math), and with the constant 128 if unsigned math was used.  Using 128 with signed math, the test didn't get optimized away.
Comment 1 Ken Raeburn 2007-08-31 07:53:51 UTC
Created attachment 14144 [details]
C test case, description and assembly in comments
Comment 2 Ken Raeburn 2007-09-02 01:43:15 UTC
After a little more experimentation, it appears that the signed-math cases that do get optimized are those with positive divisors that are not powers of two.  If the divisors are powers of two (so that the operations can be done with shifts and masks?), or are negative, then the test and abort call don't get optimized away.

(There's an edge case with INT_MIN/-1 possibly yielding undefined results without -fwrapv.  I didn't test -1, but did test a handful of other negative numbers, where the results should be fully defined.)
Comment 3 Andrew Pinski 2021-08-08 17:42:59 UTC
Fixed in GCC 10+ by r10-137.