Skip to content

Commit

Permalink
[InstCombine] Add ub-safe negation patterns (PR27817)
Browse files Browse the repository at this point in the history
  • Loading branch information
RKSimon committed Mar 23, 2020
1 parent b8a2cf6 commit 16d2065
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions llvm/test/Transforms/InstCombine/select.ll
Expand Up @@ -1348,6 +1348,29 @@ define i32 @PR27137(i32 %a) {
ret i32 %s1
}

; ub-safe negation pattern
define i32 @PR27817(i32 %x) {
; CHECK-LABEL: @PR27817(
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%cmp = icmp eq i32 %x, -2147483648
%sub = sub i32 0, %x
%sel = select i1 %cmp, i32 -2147483648, i32 %sub
ret i32 %sel
}

define i32 @PR27817_nsw(i32 %x) {
; CHECK-LABEL: @PR27817_nsw(
; CHECK-NEXT: [[SUB:%.*]] = sub i32 0, [[X:%.*]]
; CHECK-NEXT: ret i32 [[SUB]]
;
%cmp = icmp eq i32 %x, -2147483648
%sub = sub nsw i32 0, %x
%sel = select i1 %cmp, i32 -2147483648, i32 %sub
ret i32 %sel
}

define i32 @select_icmp_slt0_xor(i32 %x) {
; CHECK-LABEL: @select_icmp_slt0_xor(
; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -2147483648
Expand Down

0 comments on commit 16d2065

Please sign in to comment.