summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/onehot_merge.ll
blob: 47a4ca4b628bfd772632740e43cc9dc4ed3f70d8 (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
; RUN: opt < %s -instcombine -S | FileCheck %s

;CHECK: @and_consts
;CHECK: and i32 %k, 12
;CHECK: icmp ne i32 %0, 12
;CHECK: ret
define i1 @and_consts(i32 %k, i32 %c1, i32 %c2) {
bb:
  %tmp1 = and i32 4, %k
  %tmp2 = icmp eq i32 %tmp1, 0
  %tmp5 = and i32 8, %k
  %tmp6 = icmp eq i32 %tmp5, 0
  %or = or i1 %tmp2, %tmp6
  ret i1 %or
}

;CHECK: @foo1_and
;CHECK:  shl i32 1, %c1
;CHECK-NEXT:  lshr i32 -2147483648, %c2
;CHECK-NEXT:  or i32
;CHECK-NEXT:  and i32
;CHECK-NEXT:  icmp ne i32 %1, %0
;CHECK: ret
define i1 @foo1_and(i32 %k, i32 %c1, i32 %c2) {
bb:
  %tmp = shl i32 1, %c1
  %tmp4 = lshr i32 -2147483648, %c2
  %tmp1 = and i32 %tmp, %k
  %tmp2 = icmp eq i32 %tmp1, 0
  %tmp5 = and i32 %tmp4, %k
  %tmp6 = icmp eq i32 %tmp5, 0
  %or = or i1 %tmp2, %tmp6
  ret i1 %or
}

; Same as above but with operands commuted one of the ands, but not the other.
define i1 @foo1_and_commuted(i32 %k, i32 %c1, i32 %c2) {
; CHECK-LABEL: @foo1_and_commuted(
; CHECK-NEXT:    [[K2:%.*]] = mul i32 [[K:%.*]], [[K]]
; CHECK-NEXT:    [[TMP:%.*]] = shl i32 1, [[C1:%.*]]
; CHECK-NEXT:    [[TMP4:%.*]] = lshr i32 -2147483648, [[C2:%.*]]
; CHECK-NEXT:    [[TMP0:%.*]] = or i32 [[TMP]], [[TMP4]]
; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[K2]], [[TMP0]]
; CHECK-NEXT:    [[TMP2:%.*]] = icmp ne i32 [[TMP1]], [[TMP0]]
; CHECK-NEXT:    ret i1 [[TMP2]]
;
  %k2 = mul i32 %k, %k ; to trick the complexity sorting
  %tmp = shl i32 1, %c1
  %tmp4 = lshr i32 -2147483648, %c2
  %tmp1 = and i32 %k2, %tmp
  %tmp2 = icmp eq i32 %tmp1, 0
  %tmp5 = and i32 %tmp4, %k2
  %tmp6 = icmp eq i32 %tmp5, 0
  %or = or i1 %tmp2, %tmp6
  ret i1 %or
}

define i1 @or_consts(i32 %k, i32 %c1, i32 %c2) {
; CHECK-LABEL: @or_consts(
; CHECK-NEXT:    [[TMP1:%.*]] = and i32 [[K:%.*]], 12
; CHECK-NEXT:    [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 12
; CHECK-NEXT:    ret i1 [[TMP2]]
;
  %tmp1 = and i32 4, %k
  %tmp2 = icmp ne i32 %tmp1, 0
  %tmp5 = and i32 8, %k
  %tmp6 = icmp ne i32 %tmp5, 0
  %or = and i1 %tmp2, %tmp6
  ret i1 %or
}

define i1 @foo1_or(i32 %k, i32 %c1, i32 %c2) {
; CHECK-LABEL: @foo1_or(
; CHECK-NEXT:    [[TMP:%.*]] = shl i32 1, [[C1:%.*]]
; CHECK-NEXT:    [[TMP4:%.*]] = lshr i32 -2147483648, [[C2:%.*]]
; CHECK-NEXT:    [[TMP1:%.*]] = or i32 [[TMP]], [[TMP4]]
; CHECK-NEXT:    [[TMP2:%.*]] = and i32 [[TMP1]], [[K:%.*]]
; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP2]], [[TMP1]]
; CHECK-NEXT:    ret i1 [[TMP3]]
;
  %tmp = shl i32 1, %c1
  %tmp4 = lshr i32 -2147483648, %c2
  %tmp1 = and i32 %tmp, %k
  %tmp2 = icmp ne i32 %tmp1, 0
  %tmp5 = and i32 %tmp4, %k
  %tmp6 = icmp ne i32 %tmp5, 0
  %or = and i1 %tmp2, %tmp6
  ret i1 %or
}

; Same as above but with operands commuted one of the ors, but not the other.
define i1 @foo1_or_commuted(i32 %k, i32 %c1, i32 %c2) {
; CHECK-LABEL: @foo1_or_commuted(
; CHECK-NEXT:    [[K2:%.*]] = mul i32 [[K:%.*]], [[K]]
; CHECK-NEXT:    [[TMP:%.*]] = shl i32 1, [[C1:%.*]]
; CHECK-NEXT:    [[TMP4:%.*]] = lshr i32 -2147483648, [[C2:%.*]]
; CHECK-NEXT:    [[TMP1:%.*]] = or i32 [[TMP]], [[TMP4]]
; CHECK-NEXT:    [[TMP2:%.*]] = and i32 [[K2]], [[TMP1]]
; CHECK-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP2]], [[TMP1]]
; CHECK-NEXT:    ret i1 [[TMP3]]
;
  %k2 = mul i32 %k, %k ; to trick the complexity sorting
  %tmp = shl i32 1, %c1
  %tmp4 = lshr i32 -2147483648, %c2
  %tmp1 = and i32 %k2, %tmp
  %tmp2 = icmp ne i32 %tmp1, 0
  %tmp5 = and i32 %tmp4, %k2
  %tmp6 = icmp ne i32 %tmp5, 0
  %or = and i1 %tmp2, %tmp6
  ret i1 %or
}
OpenPOWER on IntegriCloud