[InstCombine] (-NSW x) u>= x --> x s>= 0 (PR39480)

Name: (-x) u>= x  -->  x s>= 0
%neg_x = sub nsw i8 0, %x ; %x must not be INT_MIN
%r = icmp uge i8 %neg_x, %x
  =>
%r = icmp sge i8 %x, 0

https://rise4fun.com/Alive/LLHd

https://bugs.llvm.org/show_bug.cgi?id=39480
This commit is contained in:
Roman Lebedev 2020-08-06 11:23:59 +03:00
parent 16c642fa39
commit 0e1241a3c9
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 6 additions and 2 deletions

View File

@ -3753,6 +3753,11 @@ Instruction *foldICmpXNegX(ICmpInst &I) {
NewRHS = Constant::getNullValue(X->getType());
break;
case ICmpInst::ICMP_UGE:
NewPred = ICmpInst::ICMP_SGE;
NewRHS = Constant::getNullValue(X->getType());
break;
case ICmpInst::ICMP_EQ:
case ICmpInst::ICMP_NE:
NewPred = Pred;

View File

@ -81,8 +81,7 @@ define i1 @t4(i8 %x) {
define i1 @t5(i8 %x) {
; CHECK-LABEL: @t5(
; CHECK-NEXT: [[NEG_X:%.*]] = sub nsw i8 0, [[X:%.*]]
; CHECK-NEXT: [[CMP:%.*]] = icmp uge i8 [[NEG_X]], [[X]]
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -1
; CHECK-NEXT: ret i1 [[CMP]]
;
%neg_x = sub nsw i8 0, %x