This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] canonicalize cmp/select form of uadd saturate with constant
ClosedPublic

Authored by spatel on Jan 28 2019, 12:46 PM.

Details

Summary

I'm not sure where we are in the process of optimizing the saturating/overflowing ops, so I'm circling back around to a loose end from D51929.

The backend (either CGP or DAG) doesn't recognize this pattern, so we end up with different asm for these IR variants.

Regardless of anything else, I think we want to get raw IR variations into the minimal number of raw IR forms. If/when we can canonicalize to intrinsics, that will make that step easier.

Pre: C2 == ~C1

%a = add i32 %x, C1
%c = icmp ugt i32 %x, C2
%r = select i1 %c, i32 -1, i32 %a

>

%a = add i32 %x, C1
%c2 = icmp ult i32 %x, C2
%r = select i1 %c2, i32 %a, i32 -1

https://rise4fun.com/Alive/pkH

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Jan 28 2019, 12:46 PM
spatel edited the summary of this revision. (Show Details)Jan 28 2019, 1:58 PM
This revision is now accepted and ready to land.Jan 29 2019, 8:11 AM
This revision was automatically updated to reflect the committed changes.