1
1
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2
2
; RUN: opt -instcombine -S < %s | FileCheck %s
3
3
4
+ declare void @use (i32 )
5
+
4
6
define i32 @test1 (i32 %x ) {
5
7
; CHECK-LABEL: @test1(
6
- ; CHECK-NEXT: [[AND:%.*]] = and i32 %x , 31
8
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]] , 31
7
9
; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[AND]], 63
8
10
; CHECK-NEXT: ret i32 [[SUB]]
9
11
;
@@ -14,7 +16,7 @@ define i32 @test1(i32 %x) {
14
16
15
17
define <2 x i32 > @test1vec (<2 x i32 > %x ) {
16
18
; CHECK-LABEL: @test1vec(
17
- ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> %x , <i32 31, i32 31>
19
+ ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X:%.*]] , <i32 31, i32 31>
18
20
; CHECK-NEXT: [[SUB:%.*]] = xor <2 x i32> [[AND]], <i32 63, i32 63>
19
21
; CHECK-NEXT: ret <2 x i32> [[SUB]]
20
22
;
@@ -27,7 +29,7 @@ declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
27
29
28
30
define i32 @test2 (i32 %x ) nounwind {
29
31
; CHECK-LABEL: @test2(
30
- ; CHECK-NEXT: [[COUNT:%.*]] = tail call i32 @llvm.ctlz.i32(i32 %x , i1 true)
32
+ ; CHECK-NEXT: [[COUNT:%.*]] = tail call i32 @llvm.ctlz.i32(i32 [[X:%.*]] , i1 true) [[ATTR2:#.*]], [[RNG0:!range !.*]]
31
33
; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[COUNT]], 31
32
34
; CHECK-NEXT: ret i32 [[SUB]]
33
35
;
@@ -36,15 +38,55 @@ define i32 @test2(i32 %x) nounwind {
36
38
ret i32 %sub
37
39
}
38
40
39
- define i32 @test3 (i32 %x ) {
40
- ; CHECK-LABEL: @test3 (
41
- ; CHECK-NEXT: [[AND:%.*]] = and i32 %x , 31
41
+ define i32 @xor_add (i32 %x ) {
42
+ ; CHECK-LABEL: @xor_add (
43
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]] , 31
42
44
; CHECK-NEXT: [[ADD:%.*]] = sub nuw nsw i32 73, [[AND]]
43
45
; CHECK-NEXT: ret i32 [[ADD]]
44
46
;
45
47
%and = and i32 %x , 31
46
- %sub = xor i32 31 , %and
47
- %add = add i32 %sub , 42
48
+ %xor = xor i32 %and , 31
49
+ %add = add i32 %xor , 42
50
+ ret i32 %add
51
+ }
52
+
53
+ define i32 @xor_add_extra_use (i32 %x ) {
54
+ ; CHECK-LABEL: @xor_add_extra_use(
55
+ ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 31
56
+ ; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[AND]], 31
57
+ ; CHECK-NEXT: call void @use(i32 [[XOR]])
58
+ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[XOR]], 42
59
+ ; CHECK-NEXT: ret i32 [[ADD]]
60
+ ;
61
+ %and = and i32 %x , 31
62
+ %xor = xor i32 %and , 31
63
+ call void @use (i32 %xor )
64
+ %add = add i32 %xor , 42
48
65
ret i32 %add
49
66
}
50
67
68
+ define <2 x i8 > @xor_add_splat (<2 x i8 > %x ) {
69
+ ; CHECK-LABEL: @xor_add_splat(
70
+ ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], <i8 24, i8 24>
71
+ ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[AND]], <i8 63, i8 63>
72
+ ; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw <2 x i8> [[XOR]], <i8 42, i8 42>
73
+ ; CHECK-NEXT: ret <2 x i8> [[ADD]]
74
+ ;
75
+ %and = and <2 x i8 > %x , <i8 24 , i8 24 >
76
+ %xor = xor <2 x i8 > %and , <i8 63 , i8 63 >
77
+ %add = add <2 x i8 > %xor , <i8 42 , i8 42 >
78
+ ret <2 x i8 > %add
79
+ }
80
+
81
+ define <2 x i8 > @xor_add_splat_undef (<2 x i8 > %x ) {
82
+ ; CHECK-LABEL: @xor_add_splat_undef(
83
+ ; CHECK-NEXT: [[AND:%.*]] = and <2 x i8> [[X:%.*]], <i8 24, i8 24>
84
+ ; CHECK-NEXT: [[XOR:%.*]] = xor <2 x i8> [[AND]], <i8 63, i8 undef>
85
+ ; CHECK-NEXT: [[ADD:%.*]] = add <2 x i8> [[XOR]], <i8 42, i8 42>
86
+ ; CHECK-NEXT: ret <2 x i8> [[ADD]]
87
+ ;
88
+ %and = and <2 x i8 > %x , <i8 24 , i8 24 >
89
+ %xor = xor <2 x i8 > %and , <i8 63 , i8 undef >
90
+ %add = add <2 x i8 > %xor , <i8 42 , i8 42 >
91
+ ret <2 x i8 > %add
92
+ }
0 commit comments