Skip to content

Commit 2f1229e

Browse files
committed
[Tests] Move some tests from Assembler to InstSimplify (NFC)
To make sure these are preserved when icmp constant expressions are removed.
1 parent 5ff993a commit 2f1229e

File tree

2 files changed

+100
-44
lines changed

2 files changed

+100
-44
lines changed

llvm/test/Assembler/ConstantExprNoFold.ll

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ target datalayout = "p:32:32"
1010
@A = global i64 0
1111
@B = global i64 0
1212

13-
; Don't fold this. @A might really be allocated next to @B, in which case the
14-
; icmp should return true. It's not valid to *dereference* in @B from a pointer
15-
; based on @A, but icmp isn't a dereference.
16-
17-
; CHECK: @C = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr @B)
18-
@C = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr @B)
19-
20-
; Don't fold this completely away either. In theory this could be simplified
21-
; to only use a gep on one side of the icmp though.
22-
23-
; CHECK: @D = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr getelementptr inbounds (i64, ptr @B, i64 2))
24-
@D = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr getelementptr inbounds (i64, ptr @B, i64 2))
25-
2613
; CHECK: @E = global ptr addrspace(1) addrspacecast (ptr @A to ptr addrspace(1))
2714
@E = global ptr addrspace(1) addrspacecast(ptr @A to ptr addrspace(1))
2815

@@ -31,34 +18,6 @@ target datalayout = "p:32:32"
3118
@weak.gep = global ptr getelementptr (i32, ptr @weak, i32 1)
3219
@weak = extern_weak global i32
3320

34-
; An object with weak linkage cannot have it's identity determined at compile time.
35-
; CHECK: @F = global i1 icmp eq (ptr @weakany, ptr @glob)
36-
@F = global i1 icmp eq (ptr @weakany, ptr @glob)
37-
@weakany = weak global i32 0
38-
39-
; Empty globals might end up anywhere, even on top of another global.
40-
; CHECK: @empty.cmp = global i1 icmp eq (ptr @empty.1, ptr @empty.2)
41-
@empty.1 = external global [0 x i8], align 1
42-
@empty.2 = external global [0 x i8], align 1
43-
@empty.cmp = global i1 icmp eq (ptr @empty.1, ptr @empty.2)
44-
45-
; Two unnamed_addr globals can share an address
46-
; CHECK: @unnamed.cmp = global i1 icmp eq (ptr @unnamed.1, ptr @unnamed.2)
47-
@unnamed.1 = unnamed_addr constant [5 x i8] c"asdf\00"
48-
@unnamed.2 = unnamed_addr constant [5 x i8] c"asdf\00"
49-
@unnamed.cmp = global i1 icmp eq (ptr @unnamed.1, ptr @unnamed.2)
50-
51-
@addrspace3 = internal addrspace(3) global i32 undef
52-
53-
; CHECK: @no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
54-
; CHECK: @no.fold.addrspace.icmp.eq.null.gv = global i1 icmp eq (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
55-
; CHECK: @no.fold.addrspace.icmp.ne.gv.null = global i1 icmp ne (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
56-
; CHECK: @no.fold.addrspace.icmp.ne.null.gv = global i1 icmp ne (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
57-
@no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
58-
@no.fold.addrspace.icmp.eq.null.gv = global i1 icmp eq (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
59-
@no.fold.addrspace.icmp.ne.gv.null = global i1 icmp ne (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
60-
@no.fold.addrspace.icmp.ne.null.gv = global i1 icmp ne (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
61-
6221
; Don't add an inbounds on @glob.a3, since it's not inbounds.
6322
; CHECK: @glob.a3 = alias i32, getelementptr (i32, ptr @glob.a2, i32 1)
6423
@glob = global i32 0

llvm/test/Transforms/InstSimplify/compare.ll

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,111 @@ define i1 @gep17() {
282282
ret i1 %cmp
283283
}
284284

285-
@weak = extern_weak global i8
285+
@extern_weak = extern_weak global i8
286286

287287
define i1 @extern_weak_may_be_null() {
288288
; CHECK-LABEL: @extern_weak_may_be_null(
289-
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr @weak, null
289+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr @extern_weak, null
290290
; CHECK-NEXT: ret i1 [[CMP]]
291291
;
292-
%cmp = icmp ne ptr @weak, null
292+
%cmp = icmp ne ptr @extern_weak, null
293+
ret i1 %cmp
294+
}
295+
296+
; Don't fold this. @A might really be allocated next to @B, in which case the
297+
; icmp should return true. It's not valid to *dereference* in @B from a pointer
298+
; based on @A, but icmp isn't a dereference.
299+
define i1 @globals_might_be_adjacent() {
300+
; CHECK-LABEL: @globals_might_be_adjacent(
301+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr getelementptr inbounds (i32, ptr @A, i64 1), @B
302+
; CHECK-NEXT: ret i1 [[CMP]]
303+
;
304+
%cmp = icmp eq ptr getelementptr inbounds (i32, ptr @A, i64 1), @B
305+
ret i1 %cmp
306+
}
307+
308+
define i1 @globals_might_be_adjacent2() {
309+
; CHECK-LABEL: @globals_might_be_adjacent2(
310+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr getelementptr inbounds (i64, ptr @A, i64 1), getelementptr inbounds (i64, ptr @B, i64 2)
311+
; CHECK-NEXT: ret i1 [[CMP]]
312+
;
313+
%cmp = icmp eq ptr getelementptr inbounds (i64, ptr @A, i64 1), getelementptr inbounds (i64, ptr @B, i64 2)
314+
ret i1 %cmp
315+
}
316+
317+
@weak = weak global i32 0
318+
319+
; An object with weak linkage cannot have it's identity determined at compile time.
320+
define i1 @weak_comparison() {
321+
; CHECK-LABEL: @weak_comparison(
322+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @weak, @A
323+
; CHECK-NEXT: ret i1 [[CMP]]
324+
;
325+
%cmp = icmp eq ptr @weak, @A
326+
ret i1 %cmp
327+
}
328+
329+
@empty.1 = external global [0 x i8], align 1
330+
@empty.2 = external global [0 x i8], align 1
331+
332+
; Empty globals might end up anywhere, even on top of another global.
333+
define i1 @empty_global_comparison() {
334+
; CHECK-LABEL: @empty_global_comparison(
335+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @empty.1, @empty.2
336+
; CHECK-NEXT: ret i1 [[CMP]]
337+
;
338+
%cmp = icmp eq ptr @empty.1, @empty.2
339+
ret i1 %cmp
340+
}
341+
342+
@unnamed.1 = unnamed_addr constant [5 x i8] c"asdf\00"
343+
@unnamed.2 = unnamed_addr constant [5 x i8] c"asdf\00"
344+
345+
; Two unnamed_addr globals can share an address
346+
define i1 @unnamed_addr_comparison() {
347+
; CHECK-LABEL: @unnamed_addr_comparison(
348+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @unnamed.1, @unnamed.2
349+
; CHECK-NEXT: ret i1 [[CMP]]
350+
;
351+
%cmp = icmp eq ptr @unnamed.1, @unnamed.2
352+
ret i1 %cmp
353+
}
354+
355+
@addrspace3 = internal addrspace(3) global i32 undef
356+
357+
define i1 @no.fold.addrspace.icmp.eq.gv.null() {
358+
; CHECK-LABEL: @no.fold.addrspace.icmp.eq.gv.null(
359+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(3) @addrspace3, null
360+
; CHECK-NEXT: ret i1 [[CMP]]
361+
;
362+
%cmp = icmp eq ptr addrspace(3) @addrspace3, null
363+
ret i1 %cmp
364+
}
365+
366+
define i1 @no.fold.addrspace.icmp.eq.null.gv() {
367+
; CHECK-LABEL: @no.fold.addrspace.icmp.eq.null.gv(
368+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(3) null, @addrspace3
369+
; CHECK-NEXT: ret i1 [[CMP]]
370+
;
371+
%cmp = icmp eq ptr addrspace(3) null, @addrspace3
372+
ret i1 %cmp
373+
}
374+
375+
define i1 @no.fold.addrspace.icmp.ne.gv.null() {
376+
; CHECK-LABEL: @no.fold.addrspace.icmp.ne.gv.null(
377+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(3) @addrspace3, null
378+
; CHECK-NEXT: ret i1 [[CMP]]
379+
;
380+
%cmp = icmp ne ptr addrspace(3) @addrspace3, null
381+
ret i1 %cmp
382+
}
383+
384+
define i1 @no.fold.addrspace.icmp.ne.null.gv() {
385+
; CHECK-LABEL: @no.fold.addrspace.icmp.ne.null.gv(
386+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(3) null, @addrspace3
387+
; CHECK-NEXT: ret i1 [[CMP]]
388+
;
389+
%cmp = icmp ne ptr addrspace(3) null, @addrspace3
293390
ret i1 %cmp
294391
}
295392

0 commit comments

Comments
 (0)