Skip to content

Commit

Permalink
[InstCombine] Add tests for folding (icmp eq/ne (add nuw x, y), 0);…
Browse files Browse the repository at this point in the history
… NFC
  • Loading branch information
goldsteinn committed Apr 9, 2024
1 parent 5d9d740 commit 759bab0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions llvm/test/Transforms/InstCombine/icmp-add.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3003,4 +3003,28 @@ define i1 @icmp_dec_notnonzero(i8 %x) {
ret i1 %c
}

define i1 @icmp_addnuw_nonzero(i8 %x, i8 %y) {
; CHECK-LABEL: @icmp_addnuw_nonzero(
; CHECK-NEXT: [[I:%.*]] = sub i8 0, [[Y:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[I]], [[X:%.*]]
; CHECK-NEXT: ret i1 [[C]]
;
%i = add nuw i8 %x, %y
%c = icmp eq i8 %i, 0
ret i1 %c
}

define i1 @icmp_addnuw_nonzero_fail_multiuse(i32 %x, i32 %y) {
; CHECK-LABEL: @icmp_addnuw_nonzero_fail_multiuse(
; CHECK-NEXT: [[I:%.*]] = add nuw i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[I]], 0
; CHECK-NEXT: call void @use(i32 [[I]])
; CHECK-NEXT: ret i1 [[C]]
;
%i = add nuw i32 %x, %y
%c = icmp eq i32 %i, 0
call void @use(i32 %i)
ret i1 %c
}

declare void @llvm.assume(i1)

0 comments on commit 759bab0

Please sign in to comment.