Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Reassociate drops NSW/NUW flags #12377

Open Quuxplusone opened 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR12985
Status CONFIRMED
Importance P enhancement
Reported by Andrew Trick (atrick@apple.com)
Reported on 2012-05-29 16:04:32 -0700
Last modified on 2017-06-19 12:16:39 -0700
Version trunk
Hardware PC All
CC baldrick@free.fr, llvm-bugs@lists.llvm.org, mcrosier@codeaurora.org, rafael@espindo.la
Fixed by commit(s)
Attachments rtest.ll (880 bytes, application/octet-stream)
rtest2.ll (1090 bytes, application/octet-stream)
Blocks
Blocked by
See also
Created attachment 8657
rtest.ll

The Reassociate pass unnecessarily drops NSW/NUW flags during canonicalization.
If we really want to drop the flags, we should probably do it after indvars
where we eliminate sign/zero extension.

I noticed three situations where Reassociation drops flags in a single test
case:

1. shl nsw x, c => mul x, 2**c
2. sub nsw x, y => add x, (sub 0, y)
3. add nsw (add nsw x, c1), c2 ; where c1 and c2 have opposite signs.

Attached unit tests:
rtest.ll
rtest2.ll

rtest.ll does some legitimate reassociation in order to fold constants
(exhibits case #3).

rtest2.ll has an additional use of %sub, so doesn't do any actual reassociation
or folding, and is closer to the real test case, but it still drops flags
everywhere.

rtest2.ll would probably be easier to fix (no case #3), but it would be nice to
handle rtest.ll too. It would be a nice property to preserve the flags if
possible regardless of the number of uses
Quuxplusone commented 12 years ago

Attached rtest.ll (880 bytes, application/octet-stream): rtest.ll

Quuxplusone commented 12 years ago

Attached rtest2.ll (1090 bytes, application/octet-stream): rtest2.ll

Quuxplusone commented 12 years ago

This should be straight-forward to fix.

Quuxplusone commented 9 years ago
1. shl nsw x, c => mul x, 2**c

Mostly addressed in rr21555.
Quuxplusone commented 9 years ago
(In reply to comment #3)
> 1. shl nsw x, c => mul x, 2**c
>
> Mostly addressed in rr2155

Errr.. r221555.