This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Propagate the nsw/nuw flags from the add in the 'shifty' abs pattern to the sub in the select version.
ClosedPublic

Authored by craig.topper on May 16 2018, 4:14 PM.

Details

Summary

According to alive this is valid. I'm hoping to use this to make an assumption that the sign bit is zero after this sequence. The only way it wouldn't be is if the input was INT__MIN, but by preserving the flags we can make doing this to INT_MIN UB.

The nuw flags is weird because it creates such a contradiction that the original number would have to be positive meaning we could remove the select entirely, but we don't get that far.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.May 16 2018, 4:14 PM
spatel accepted this revision.May 17 2018, 6:38 AM

LGTM.

This revision is now accepted and ready to land.May 17 2018, 6:38 AM
This revision was automatically updated to reflect the committed changes.