This is an archive of the discontinued LLVM Phabricator instance.

[ARM][CGP] Skip nuw values in PrepareConstants
ClosedPublic

Authored by samparker on May 17 2019, 2:26 AM.

Details

Summary

PrepareConstants step converts add/sub with 'negative' immediates to sub/add with a 'positive' imm to make promotion more simple. nuw already states that the add shouldn't cause an unsigned overflow, so it shouldn't need any tweaking. Plus, we also don't allow a sub with a 'negative' immediate to be safe underflow, so this functionality has been removed. The PrepareConstants step now just handles the add instructions that we've determined would be safe if they underflow.

Diff Detail

Repository
rL LLVM

Event Timeline

samparker created this revision.May 17 2019, 2:26 AM
SjoerdMeijer added inline comments.May 17 2019, 8:05 AM
lib/Target/ARM/ARMCodeGenPrepare.cpp
480 ↗(On Diff #199999)

Perhaps you can be more specific here:

adds that safely wrap

This is for unsigned values for which behaviour is well defined as wrapping or modulo behaviour.

The Instructions that exhibit this behaviour are added to a list SafeUnderflow in function isSafeOverflow, which all looks a bit inconsistent (yep, I'm bikeshedding names ;-)).

samparker updated this revision to Diff 200241.May 20 2019, 3:52 AM

Cheers! I've swapped out 'overflow' and 'underflow' terms for wrap.

SjoerdMeijer accepted this revision.May 20 2019, 7:55 AM

Looks like a good improvement to me.

lib/Target/ARM/ARMCodeGenPrepare.cpp
305 ↗(On Diff #200241)

Looking at this example and comment again, we are explaining that this is not equivalent:

%sub = sub i8 %a, 2
%cmp = icmp ule i8 %sub, 254
=>
%a32 = zext i8 %a to i32
%sub1 = sub i32 %a32, 2
%cmp = icmp ule i32 %sub1, 254

and alive agrees with us :-) and gives the same values: https://rise4fun.com/Alive/6gzR

And changing the sub to a sub with constant 1 shows it is all good.

This revision is now accepted and ready to land.May 20 2019, 7:55 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 21 2019, 12:54 AM