HomePhabricator

[InstCombine] foldICmpBinOp(): consider inverted check in 'unsigned sub…

Authored by lebedev.ri on Thu, Sep 5, 10:41 AM.

Description

[InstCombine] foldICmpBinOp(): consider inverted check in 'unsigned sub overflow' check

A follow-up for r329011.
This may be changed to produce @llvm.sub.with.overflow in a later patch,
but for now just make things more consistent overall.

A few observations stem from this:

  • There does not seem to be a similar one-instruction fold for uadd-overflow
  • I'm not sure we'll want to canonicalize B u> A as usub.with.overflow, so since the icmp here no longer refers to sub, reconstructing usub.with.overflow will be problematic, and will likely require standalone pass (similar to DivRemPairs).

https://rise4fun.com/Alive/Zqs

Name: (A - B) u> A --> B u> A

%t0 = sub i8 %A, %B
%r = icmp ugt i8 %t0, %A

>

%r = icmp ugt i8 %B, %A

Name: (A - B) u<= A --> B u<= A

%t0 = sub i8 %A, %B
%r = icmp ule i8 %t0, %A

>

%r = icmp ule i8 %B, %A

Name: C u< (C - D) --> C u< D

%t0 = sub i8 %C, %D
%r = icmp ult i8 %C, %t0

>

%r = icmp ult i8 %C, %D

Name: C u>= (C - D) --> C u>= D

%t0 = sub i8 %C, %D
%r = icmp uge i8 %C, %t0

>

%r = icmp uge i8 %C, %D

llvm-svn: 371101

Details

Committed
lebedev.riThu, Sep 5, 10:41 AM
Parents
rGecb7ea1ae7c6: [InstCombine] foldICmpBinOp(): consider inverted check in 'unsigned add…
Branches
Unknown
Tags
Unknown

Event Timeline

xbolva00 added inline comments.
/llvm/test/Transforms/InstCombine/unsigned-sub-lack-of-overflow-check.ll
7

The comment does not describe current IR

Fixme/todo?