@@ -14,6 +14,32 @@ define i64 @test_inbounds([0 x i32]* %base, i64 %idx) {
14
14
ret i64 %d
15
15
}
16
16
17
+ define i64 @test_partial_inbounds1 ([0 x i32 ]* %base , i64 %idx ) {
18
+ ; CHECK-LABEL: @test_partial_inbounds1(
19
+ ; CHECK-NEXT: [[P2_IDX:%.*]] = shl i64 [[IDX:%.*]], 2
20
+ ; CHECK-NEXT: ret i64 [[P2_IDX]]
21
+ ;
22
+ %p1 = getelementptr inbounds [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 0
23
+ %p2 = getelementptr [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 %idx
24
+ %i1 = ptrtoint i32* %p1 to i64
25
+ %i2 = ptrtoint i32* %p2 to i64
26
+ %d = sub i64 %i2 , %i1
27
+ ret i64 %d
28
+ }
29
+
30
+ define i64 @test_partial_inbounds2 ([0 x i32 ]* %base , i64 %idx ) {
31
+ ; CHECK-LABEL: @test_partial_inbounds2(
32
+ ; CHECK-NEXT: [[P2_IDX:%.*]] = shl nsw i64 [[IDX:%.*]], 2
33
+ ; CHECK-NEXT: ret i64 [[P2_IDX]]
34
+ ;
35
+ %p1 = getelementptr [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 0
36
+ %p2 = getelementptr inbounds [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 %idx
37
+ %i1 = ptrtoint i32* %p1 to i64
38
+ %i2 = ptrtoint i32* %p2 to i64
39
+ %d = sub i64 %i2 , %i1
40
+ ret i64 %d
41
+ }
42
+
17
43
define i64 @test_inbounds_nuw ([0 x i32 ]* %base , i64 %idx ) {
18
44
; CHECK-LABEL: @test_inbounds_nuw(
19
45
; CHECK-NEXT: [[P2_IDX:%.*]] = shl nuw nsw i64 [[IDX:%.*]], 2
@@ -69,13 +95,39 @@ define i64 @test_inbounds_nuw_swapped([0 x i32]* %base, i64 %idx) {
69
95
ret i64 %d
70
96
}
71
97
98
+ define i64 @test_inbounds1_nuw_swapped ([0 x i32 ]* %base , i64 %idx ) {
99
+ ; CHECK-LABEL: @test_inbounds1_nuw_swapped(
100
+ ; CHECK-NEXT: [[P2_IDX_NEG:%.*]] = mul i64 [[IDX:%.*]], -4
101
+ ; CHECK-NEXT: ret i64 [[P2_IDX_NEG]]
102
+ ;
103
+ %p1 = getelementptr inbounds [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 0
104
+ %p2 = getelementptr [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 %idx
105
+ %i1 = ptrtoint i32* %p2 to i64
106
+ %i2 = ptrtoint i32* %p1 to i64
107
+ %d = sub nuw i64 %i2 , %i1
108
+ ret i64 %d
109
+ }
110
+
111
+ define i64 @test_inbounds2_nuw_swapped ([0 x i32 ]* %base , i64 %idx ) {
112
+ ; CHECK-LABEL: @test_inbounds2_nuw_swapped(
113
+ ; CHECK-NEXT: [[P2_IDX_NEG:%.*]] = mul i64 [[IDX:%.*]], -4
114
+ ; CHECK-NEXT: ret i64 [[P2_IDX_NEG]]
115
+ ;
116
+ %p1 = getelementptr [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 0
117
+ %p2 = getelementptr inbounds [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 %idx
118
+ %i1 = ptrtoint i32* %p2 to i64
119
+ %i2 = ptrtoint i32* %p1 to i64
120
+ %d = sub nuw i64 %i2 , %i1
121
+ ret i64 %d
122
+ }
123
+
72
124
; The sub and shl here could be nuw, but this is harder to handle.
73
125
define i64 @test_inbounds_nuw_two_gep ([0 x i32 ]* %base , i64 %idx , i64 %idx2 ) {
74
126
; CHECK-LABEL: @test_inbounds_nuw_two_gep(
75
127
; CHECK-NEXT: [[P1_IDX_NEG:%.*]] = mul i64 [[IDX:%.*]], -4
76
128
; CHECK-NEXT: [[P2_IDX_NEG_NEG:%.*]] = shl i64 [[IDX2:%.*]], 2
77
- ; CHECK-NEXT: [[DOTNEG :%.*]] = add i64 [[P2_IDX_NEG_NEG]], [[P1_IDX_NEG]]
78
- ; CHECK-NEXT: ret i64 [[DOTNEG ]]
129
+ ; CHECK-NEXT: [[GEPDIFF_NEG :%.*]] = add i64 [[P2_IDX_NEG_NEG]], [[P1_IDX_NEG]]
130
+ ; CHECK-NEXT: ret i64 [[GEPDIFF_NEG ]]
79
131
;
80
132
%p1 = getelementptr inbounds [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 %idx
81
133
%p2 = getelementptr inbounds [0 x i32 ], [0 x i32 ]* %base , i64 0 , i64 %idx2
0 commit comments