diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-04-02 20:37:40 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-04-02 20:37:40 +0000 |
| commit | cbb0450540ed03d3c630996cbb8ef719a8f6b6d5 (patch) | |
| tree | 6e2396373f5e266b24d2bd3816f12237ef4d0597 /llvm/lib | |
| parent | be0442eeaaefbce1e3ed1f0f1af5b7044544b99f (diff) | |
| download | bcm5719-llvm-cbb0450540ed03d3c630996cbb8ef719a8f6b6d5.tar.gz bcm5719-llvm-cbb0450540ed03d3c630996cbb8ef719a8f6b6d5.zip | |
[InstCombine] add folds for icmp + sub (PR36969)
(A - B) >u A --> A <u B
C <u (C - D) --> C <u D
https://rise4fun.com/Alive/e7j
Name: ugt
%sub = sub i8 %x, %y
%cmp = icmp ugt i8 %sub, %x
=>
%cmp = icmp ult i8 %x, %y
Name: ult
%sub = sub i8 %x, %y
%cmp = icmp ult i8 %x, %sub
=>
%cmp = icmp ult i8 %x, %y
This should fix:
https://bugs.llvm.org/show_bug.cgi?id=36969
llvm-svn: 329011
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index c0876a27594..cea3a1d705b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3005,17 +3005,22 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) { // icmp (X-Y), X -> icmp 0, Y for equalities or if there is no overflow. if (A == Op1 && NoOp0WrapProblem) return new ICmpInst(Pred, Constant::getNullValue(Op1->getType()), B); - // icmp X, (X-Y) -> icmp Y, 0 for equalities or if there is no overflow. if (C == Op0 && NoOp1WrapProblem) return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType())); + // (A - B) >u A --> A <u B + if (A == Op1 && Pred == ICmpInst::ICMP_UGT) + return new ICmpInst(ICmpInst::ICMP_ULT, A, B); + // C <u (C - D) --> C <u D + if (C == Op0 && Pred == ICmpInst::ICMP_ULT) + return new ICmpInst(ICmpInst::ICMP_ULT, C, D); + // icmp (Y-X), (Z-X) -> icmp Y, Z for equalities or if there is no overflow. if (B && D && B == D && NoOp0WrapProblem && NoOp1WrapProblem && // Try not to increase register pressure. BO0->hasOneUse() && BO1->hasOneUse()) return new ICmpInst(Pred, A, C); - // icmp (X-Y), (X-Z) -> icmp Z, Y for equalities or if there is no overflow. if (A && C && A == C && NoOp0WrapProblem && NoOp1WrapProblem && // Try not to increase register pressure. |

