summaryrefslogtreecommitdiff
path: root/test/Transforms/InstCombine/icmp-logical.ll
blob: c0c5a61ef04e4f31b97ec819f94996202398fdcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
; 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
}