[llvm] 2f1229e - [Tests] Move some tests from Assembler to InstSimplify (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 06:00:33 PDT 2024
Author: Nikita Popov
Date: 2024-06-03T15:00:25+02:00
New Revision: 2f1229e40ecc200f76da1864cd0861a4c51bf917
URL: https://github.com/llvm/llvm-project/commit/2f1229e40ecc200f76da1864cd0861a4c51bf917
DIFF: https://github.com/llvm/llvm-project/commit/2f1229e40ecc200f76da1864cd0861a4c51bf917.diff
LOG: [Tests] Move some tests from Assembler to InstSimplify (NFC)
To make sure these are preserved when icmp constant expressions
are removed.
Added:
Modified:
llvm/test/Assembler/ConstantExprNoFold.ll
llvm/test/Transforms/InstSimplify/compare.ll
Removed:
################################################################################
diff --git a/llvm/test/Assembler/ConstantExprNoFold.ll b/llvm/test/Assembler/ConstantExprNoFold.ll
index a676a0c7eb36a..862e0c2814931 100644
--- a/llvm/test/Assembler/ConstantExprNoFold.ll
+++ b/llvm/test/Assembler/ConstantExprNoFold.ll
@@ -10,19 +10,6 @@ target datalayout = "p:32:32"
@A = global i64 0
@B = global i64 0
-; Don't fold this. @A might really be allocated next to @B, in which case the
-; icmp should return true. It's not valid to *dereference* in @B from a pointer
-; based on @A, but icmp isn't a dereference.
-
-; CHECK: @C = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr @B)
- at C = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr @B)
-
-; Don't fold this completely away either. In theory this could be simplified
-; to only use a gep on one side of the icmp though.
-
-; CHECK: @D = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr getelementptr inbounds (i64, ptr @B, i64 2))
- at D = global i1 icmp eq (ptr getelementptr inbounds (i64, ptr @A, i64 1), ptr getelementptr inbounds (i64, ptr @B, i64 2))
-
; CHECK: @E = global ptr addrspace(1) addrspacecast (ptr @A to ptr addrspace(1))
@E = global ptr addrspace(1) addrspacecast(ptr @A to ptr addrspace(1))
@@ -31,34 +18,6 @@ target datalayout = "p:32:32"
@weak.gep = global ptr getelementptr (i32, ptr @weak, i32 1)
@weak = extern_weak global i32
-; An object with weak linkage cannot have it's identity determined at compile time.
-; CHECK: @F = global i1 icmp eq (ptr @weakany, ptr @glob)
- at F = global i1 icmp eq (ptr @weakany, ptr @glob)
- at weakany = weak global i32 0
-
-; Empty globals might end up anywhere, even on top of another global.
-; CHECK: @empty.cmp = global i1 icmp eq (ptr @empty.1, ptr @empty.2)
- at empty.1 = external global [0 x i8], align 1
- at empty.2 = external global [0 x i8], align 1
- at empty.cmp = global i1 icmp eq (ptr @empty.1, ptr @empty.2)
-
-; Two unnamed_addr globals can share an address
-; CHECK: @unnamed.cmp = global i1 icmp eq (ptr @unnamed.1, ptr @unnamed.2)
- at unnamed.1 = unnamed_addr constant [5 x i8] c"asdf\00"
- at unnamed.2 = unnamed_addr constant [5 x i8] c"asdf\00"
- at unnamed.cmp = global i1 icmp eq (ptr @unnamed.1, ptr @unnamed.2)
-
- at addrspace3 = internal addrspace(3) global i32 undef
-
-; CHECK: @no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
-; CHECK: @no.fold.addrspace.icmp.eq.null.gv = global i1 icmp eq (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
-; CHECK: @no.fold.addrspace.icmp.ne.gv.null = global i1 icmp ne (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
-; CHECK: @no.fold.addrspace.icmp.ne.null.gv = global i1 icmp ne (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
- at no.fold.addrspace.icmp.eq.gv.null = global i1 icmp eq (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
- at no.fold.addrspace.icmp.eq.null.gv = global i1 icmp eq (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
- at no.fold.addrspace.icmp.ne.gv.null = global i1 icmp ne (ptr addrspace(3) @addrspace3, ptr addrspace(3) null)
- at no.fold.addrspace.icmp.ne.null.gv = global i1 icmp ne (ptr addrspace(3) null, ptr addrspace(3) @addrspace3)
-
; Don't add an inbounds on @glob.a3, since it's not inbounds.
; CHECK: @glob.a3 = alias i32, getelementptr (i32, ptr @glob.a2, i32 1)
@glob = global i32 0
diff --git a/llvm/test/Transforms/InstSimplify/compare.ll b/llvm/test/Transforms/InstSimplify/compare.ll
index d975b77469691..9c213d526d53d 100644
--- a/llvm/test/Transforms/InstSimplify/compare.ll
+++ b/llvm/test/Transforms/InstSimplify/compare.ll
@@ -282,14 +282,111 @@ define i1 @gep17() {
ret i1 %cmp
}
- at weak = extern_weak global i8
+ at extern_weak = extern_weak global i8
define i1 @extern_weak_may_be_null() {
; CHECK-LABEL: @extern_weak_may_be_null(
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr @weak, null
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr @extern_weak, null
; CHECK-NEXT: ret i1 [[CMP]]
;
- %cmp = icmp ne ptr @weak, null
+ %cmp = icmp ne ptr @extern_weak, null
+ ret i1 %cmp
+}
+
+; Don't fold this. @A might really be allocated next to @B, in which case the
+; icmp should return true. It's not valid to *dereference* in @B from a pointer
+; based on @A, but icmp isn't a dereference.
+define i1 @globals_might_be_adjacent() {
+; CHECK-LABEL: @globals_might_be_adjacent(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr getelementptr inbounds (i32, ptr @A, i64 1), @B
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp eq ptr getelementptr inbounds (i32, ptr @A, i64 1), @B
+ ret i1 %cmp
+}
+
+define i1 @globals_might_be_adjacent2() {
+; CHECK-LABEL: @globals_might_be_adjacent2(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr getelementptr inbounds (i64, ptr @A, i64 1), getelementptr inbounds (i64, ptr @B, i64 2)
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp eq ptr getelementptr inbounds (i64, ptr @A, i64 1), getelementptr inbounds (i64, ptr @B, i64 2)
+ ret i1 %cmp
+}
+
+ at weak = weak global i32 0
+
+; An object with weak linkage cannot have it's identity determined at compile time.
+define i1 @weak_comparison() {
+; CHECK-LABEL: @weak_comparison(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @weak, @A
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp eq ptr @weak, @A
+ ret i1 %cmp
+}
+
+ at empty.1 = external global [0 x i8], align 1
+ at empty.2 = external global [0 x i8], align 1
+
+; Empty globals might end up anywhere, even on top of another global.
+define i1 @empty_global_comparison() {
+; CHECK-LABEL: @empty_global_comparison(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @empty.1, @empty.2
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp eq ptr @empty.1, @empty.2
+ ret i1 %cmp
+}
+
+ at unnamed.1 = unnamed_addr constant [5 x i8] c"asdf\00"
+ at unnamed.2 = unnamed_addr constant [5 x i8] c"asdf\00"
+
+; Two unnamed_addr globals can share an address
+define i1 @unnamed_addr_comparison() {
+; CHECK-LABEL: @unnamed_addr_comparison(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr @unnamed.1, @unnamed.2
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp eq ptr @unnamed.1, @unnamed.2
+ ret i1 %cmp
+}
+
+ at addrspace3 = internal addrspace(3) global i32 undef
+
+define i1 @no.fold.addrspace.icmp.eq.gv.null() {
+; CHECK-LABEL: @no.fold.addrspace.icmp.eq.gv.null(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(3) @addrspace3, null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp eq ptr addrspace(3) @addrspace3, null
+ ret i1 %cmp
+}
+
+define i1 @no.fold.addrspace.icmp.eq.null.gv() {
+; CHECK-LABEL: @no.fold.addrspace.icmp.eq.null.gv(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(3) null, @addrspace3
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp eq ptr addrspace(3) null, @addrspace3
+ ret i1 %cmp
+}
+
+define i1 @no.fold.addrspace.icmp.ne.gv.null() {
+; CHECK-LABEL: @no.fold.addrspace.icmp.ne.gv.null(
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(3) @addrspace3, null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp ne ptr addrspace(3) @addrspace3, null
+ ret i1 %cmp
+}
+
+define i1 @no.fold.addrspace.icmp.ne.null.gv() {
+; CHECK-LABEL: @no.fold.addrspace.icmp.ne.null.gv(
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(3) null, @addrspace3
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %cmp = icmp ne ptr addrspace(3) null, @addrspace3
ret i1 %cmp
}
More information about the llvm-commits
mailing list