-
Notifications
You must be signed in to change notification settings - Fork 13.5k
SimplifyCFG switch
removal should add no-wrap flags when possible
#59671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Edit: Sorry I misunderstand the related pass and just have seen the partial IR result(missing data layout) https://llvm.godbolt.org/z/7saozhM5K.
|
reduced case for opt -O3, (SimplifyCFG switch-to-lookup depends on native integer widths) |
Does the missing nsw flag actually matter for some following optimization? |
The last part of this has landed in https://reviews.llvm.org/D150943, so closing this issue. We how produce |
Thanks nikic! I forget specifically what I was looking at back when I opened this, so I'm not certain what, if anything, needed it. My guess would be something like a |
Today, LLVM optimizes
down to
That's a huge improvement, but it could be slightly better as a
sub nsw
instead: https://alive2.llvm.org/ce/z/GZs_djIf I'm understanding things right, SimplifyCFG turns the switch into
but in this case it could (https://alive2.llvm.org/ce/z/XzPeQv) have those be
sub nsw
,mul nsw
, andadd nsw
, to better preserve the knowledge of the limited input range -- or maybe special case switches that map0
to0
to just emitmul nsw
(ornuw
) when legal without the extrasub
/add
complication.Then something else (instcombine?) could take advantage of those
nsw
flags to optimize down to just thesub nsw i8, 0, %x
: https://alive2.llvm.org/ce/z/tESh4R. But it looks like they got lost right now (https://llvm.godbolt.org/z/3dMW8j1sr), so maybe there'd be more work there too. (If SimplifyCFG left off thesub
/add
, though, and just had themul nsw
, then InstCombine looks like it would already preserve thensw
to thesub
https://llvm.godbolt.org/z/9der4sraG.)Original rust exploration that led me here: https://rust.godbolt.org/z/EW1aba8Mr
The text was updated successfully, but these errors were encountered: