llvm-6502/test/Transforms/InstCombine/icmp-logical.ll
Tim Northover 0415b1810b InstCombine: allow unmasked icmps to be combined with logical ops
"(icmp op i8 A, B)" is equivalent to "(icmp op i8 (A & 0xff), B)" as a
degenerate case. Allowing this as a "masked" comparison when analysing "(icmp)
&/| (icmp)" allows us to combine them in more cases.

rdar://problem/7625728

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189931 91177308-0d34-0410-b5e6-96231b3b80d8
2013-09-04 11:57:17 +00:00

153 lines
3.1 KiB
LLVM

; RUN: opt -instcombine -S -o - %s | FileCheck %s
define i1 @masked_and_notallzeroes(i32 %A) {
; CHECK-LABEL: @masked_and_notallzeroes
; CHECK: [[MASK:%.*]] = and i32 %A, 7
; CHECK: icmp ne i32 [[MASK]], 0
; CHECK-NOT: and i32 %A, 39
; CHECK: ret i1
%mask1 = and i32 %A, 7
%tst1 = icmp ne i32 %mask1, 0
%mask2 = and i32 %A, 39
%tst2 = icmp ne i32 %mask2, 0
%res = and i1 %tst1, %tst2
ret i1 %res
}
define i1 @masked_or_allzeroes(i32 %A) {
; CHECK-LABEL: @masked_or_allzeroes
; CHECK: [[MASK:%.*]] = and i32 %A, 7
; CHECK: icmp eq i32 [[MASK]], 0
; CHECK-NOT: and i32 %A, 39
; CHECK: ret i1
%mask1 = and i32 %A, 7
%tst1 = icmp eq i32 %mask1, 0
%mask2 = and i32 %A, 39
%tst2 = icmp eq i32 %mask2, 0
%res = or i1 %tst1, %tst2
ret i1 %res
}
define i1 @masked_and_notallones(i32 %A) {
; CHECK-LABEL: @masked_and_notallones
; CHECK: [[MASK:%.*]] = and i32 %A, 7
; CHECK: icmp ne i32 [[MASK]], 7
; CHECK-NOT: and i32 %A, 39
; CHECK: ret i1
%mask1 = and i32 %A, 7
%tst1 = icmp ne i32 %mask1, 7
%mask2 = and i32 %A, 39
%tst2 = icmp ne i32 %mask2, 39
%res = and i1 %tst1, %tst2
ret i1 %res
}
define i1 @masked_or_allones(i32 %A) {
; CHECK-LABEL: @masked_or_allones
; CHECK: [[MASK:%.*]] = and i32 %A, 7
; CHECK: icmp eq i32 [[MASK]], 7
; CHECK-NOT: and i32 %A, 39
; CHECK: ret i1
%mask1 = and i32 %A, 7
%tst1 = icmp eq i32 %mask1, 7
%mask2 = and i32 %A, 39
%tst2 = icmp eq i32 %mask2, 39
%res = or i1 %tst1, %tst2
ret i1 %res
}
define i1 @masked_and_notA(i32 %A) {
; CHECK-LABEL: @masked_and_notA
; CHECK: [[MASK:%.*]] = and i32 %A, 39
; CHECK: icmp ne i32 [[MASK]], %A
; CHECK-NOT: and i32 %A, 7
; CHECK: ret i1
%mask1 = and i32 %A, 7
%tst1 = icmp ne i32 %mask1, %A
%mask2 = and i32 %A, 39
%tst2 = icmp ne i32 %mask2, %A
%res = and i1 %tst1, %tst2
ret i1 %res
}
define i1 @masked_or_A(i32 %A) {
; CHECK-LABEL: @masked_or_A
; CHECK: [[MASK:%.*]] = and i32 %A, 39
; CHECK: icmp eq i32 [[MASK]], %A
; CHECK-NOT: and i32 %A, 7
; CHECK: ret i1
%mask1 = and i32 %A, 7
%tst1 = icmp eq i32 %mask1, %A
%mask2 = and i32 %A, 39
%tst2 = icmp eq i32 %mask2, %A
%res = or i1 %tst1, %tst2
ret i1 %res
}
define i1 @masked_or_allzeroes_notoptimised(i32 %A) {
; CHECK-LABEL: @masked_or_allzeroes_notoptimised
; CHECK: [[MASK:%.*]] = and i32 %A, 15
; CHECK: icmp eq i32 [[MASK]], 0
; CHECK: [[MASK:%.*]] = and i32 %A, 39
; CHECK: icmp eq i32 [[MASK]], 0
; CHECK: ret i1
%mask1 = and i32 %A, 15
%tst1 = icmp eq i32 %mask1, 0
%mask2 = and i32 %A, 39
%tst2 = icmp eq i32 %mask2, 0
%res = or i1 %tst1, %tst2
ret i1 %res
}
define i1 @nomask_lhs(i32 %in) {
; CHECK-LABEL: @nomask_lhs
; CHECK: [[MASK:%.*]] = and i32 %in, 1
; CHECK: icmp eq i32 [[MASK]], 0
; CHECK-NOT: icmp
; CHECK: ret i1
%tst1 = icmp eq i32 %in, 0
%masked = and i32 %in, 1
%tst2 = icmp eq i32 %masked, 0
%val = or i1 %tst1, %tst2
ret i1 %val
}
define i1 @nomask_rhs(i32 %in) {
; CHECK-LABEL: @nomask_rhs
; CHECK: [[MASK:%.*]] = and i32 %in, 1
; CHECK: icmp eq i32 [[MASK]], 0
; CHECK-NOT: icmp
; CHECK: ret i1
%masked = and i32 %in, 1
%tst1 = icmp eq i32 %masked, 0
%tst2 = icmp eq i32 %in, 0
%val = or i1 %tst1, %tst2
ret i1 %val
}