Skip to content

Commit

Permalink
[InstCombine] Add tests for folding (icmp eq/ne (xor x, C0), C1); NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
goldsteinn committed Jun 7, 2024
1 parent c6e9371 commit 27084f7
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion llvm/test/Transforms/InstCombine/icmp-equality-xor.ll
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ define i1 @cmpeq_xor_cst1_commuted(i32 %a, i32 %b) {
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP1]], 10
; CHECK-NEXT: ret i1 [[CMP]]
;
%b2 = mul i32 %b, %b ; thwart complexity-based canonicalization
%b2 = mul i32 %b, %b ; thwart complexity-based canonicalization
%c = xor i32 %a, 10
%cmp = icmp eq i32 %b2, %c
ret i1 %cmp
Expand Down Expand Up @@ -145,3 +145,43 @@ entry:
%cmp = icmp ne <2 x i8> %xor, <i8 9, i8 79>
ret <2 x i1> %cmp
}

declare void @use.i8(i8)
define i1 @fold_xorC_eq0_multiuse(i8 %x, i8 %y) {
; CHECK-LABEL: @fold_xorC_eq0_multiuse(
; CHECK-NEXT: [[XX:%.*]] = xor i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[XX]], 0
; CHECK-NEXT: call void @use.i8(i8 [[XX]])
; CHECK-NEXT: ret i1 [[R]]
;
%xx = xor i8 %x, %y
%r = icmp eq i8 %xx, 0
call void @use.i8(i8 %xx)
ret i1 %r
}

define i1 @fold_xorC_eq1_multiuse_fail(i8 %x, i8 %y) {
; CHECK-LABEL: @fold_xorC_eq1_multiuse_fail(
; CHECK-NEXT: [[XX:%.*]] = xor i8 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[XX]], 1
; CHECK-NEXT: call void @use.i8(i8 [[XX]])
; CHECK-NEXT: ret i1 [[R]]
;
%xx = xor i8 %x, %y
%r = icmp eq i8 %xx, 1
call void @use.i8(i8 %xx)
ret i1 %r
}

define i1 @fold_xorC_neC_multiuse(i8 %x) {
; CHECK-LABEL: @fold_xorC_neC_multiuse(
; CHECK-NEXT: [[XX:%.*]] = xor i8 [[X:%.*]], 45
; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[XX]], 67
; CHECK-NEXT: call void @use.i8(i8 [[XX]])
; CHECK-NEXT: ret i1 [[R]]
;
%xx = xor i8 %x, 45
%r = icmp ne i8 %xx, 67
call void @use.i8(i8 %xx)
ret i1 %r
}

0 comments on commit 27084f7

Please sign in to comment.