[llvm] ed1c1da - [SCCP] Add tests for more non-null roots (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 06:18:05 PDT 2024
Author: Nikita Popov
Date: 2024-08-27T15:17:51+02:00
New Revision: ed1c1da04804ac7e355426922f6e1579a90e4ff1
URL: https://github.com/llvm/llvm-project/commit/ed1c1da04804ac7e355426922f6e1579a90e4ff1
DIFF: https://github.com/llvm/llvm-project/commit/ed1c1da04804ac7e355426922f6e1579a90e4ff1.diff
LOG: [SCCP] Add tests for more non-null roots (NFC)
Added:
Modified:
llvm/test/Transforms/SCCP/pointer-nonnull.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/SCCP/pointer-nonnull.ll b/llvm/test/Transforms/SCCP/pointer-nonnull.ll
index a88f08ab25fe1d..54ec04fbdeb176 100644
--- a/llvm/test/Transforms/SCCP/pointer-nonnull.ll
+++ b/llvm/test/Transforms/SCCP/pointer-nonnull.ll
@@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=sccp < %s | FileCheck %s
+declare ptr @get()
+
define i1 @test_no_attr(ptr %p) {
; CHECK-LABEL: define i1 @test_no_attr(
; CHECK-SAME: ptr [[P:%.*]]) {
@@ -38,6 +40,73 @@ define i1 @test_dereferenceable(ptr dereferenceable(4) %p) {
ret i1 %cmp
}
+define i1 @test_alloca() {
+; CHECK-LABEL: define i1 @test_alloca() {
+; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[A]], null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %a = alloca i32
+ %cmp = icmp ne ptr %a, null
+ ret i1 %cmp
+}
+
+define i1 @test_alloca_addrspace() {
+; CHECK-LABEL: define i1 @test_alloca_addrspace() {
+; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4, addrspace(1)
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr addrspace(1) [[A]], null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %a = alloca i32, addrspace(1)
+ %cmp = icmp ne ptr addrspace(1) %a, null
+ ret i1 %cmp
+}
+
+define i1 @test_alloca_null_pointer_valid() null_pointer_is_valid {
+; CHECK-LABEL: define i1 @test_alloca_null_pointer_valid(
+; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[A]], null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %a = alloca i32
+ %cmp = icmp ne ptr %a, null
+ ret i1 %cmp
+}
+
+define i1 @test_load_nonnull(ptr %p) {
+; CHECK-LABEL: define i1 @test_load_nonnull(
+; CHECK-SAME: ptr [[P:%.*]]) {
+; CHECK-NEXT: [[P2:%.*]] = load ptr, ptr [[P]], align 8, !nonnull [[META0:![0-9]+]]
+; CHECK-NEXT: ret i1 true
+;
+ %p2 = load ptr, ptr %p, !nonnull !{}
+ %cmp = icmp ne ptr %p2, null
+ ret i1 %cmp
+}
+
+define i1 @test_call_nonnull() {
+; CHECK-LABEL: define i1 @test_call_nonnull() {
+; CHECK-NEXT: [[P:%.*]] = call nonnull ptr @get()
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[P]], null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %p = call nonnull ptr @get()
+ %cmp = icmp ne ptr %p, null
+ ret i1 %cmp
+}
+
+define i1 @test_call_dereferenceable() {
+; CHECK-LABEL: define i1 @test_call_dereferenceable() {
+; CHECK-NEXT: [[P:%.*]] = call dereferenceable(4) ptr @get()
+; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[P]], null
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %p = call dereferenceable(4) ptr @get()
+ %cmp = icmp ne ptr %p, null
+ ret i1 %cmp
+}
+
define i1 @test_gep_no_flags(ptr nonnull %p, i64 %x) {
; CHECK-LABEL: define i1 @test_gep_no_flags(
; CHECK-SAME: ptr nonnull [[P:%.*]], i64 [[X:%.*]]) {
@@ -74,7 +143,7 @@ define i1 @test_gep_inbounds(ptr nonnull %p, i64 %x) {
define i1 @test_gep_inbounds_null_pointer_valid(ptr nonnull %p, i64 %x) null_pointer_is_valid {
; CHECK-LABEL: define i1 @test_gep_inbounds_null_pointer_valid(
-; CHECK-SAME: ptr nonnull [[P:%.*]], i64 [[X:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-SAME: ptr nonnull [[P:%.*]], i64 [[X:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[X]]
; CHECK-NEXT: [[CMP:%.*]] = icmp ne ptr [[GEP]], null
; CHECK-NEXT: ret i1 [[CMP]]
@@ -135,3 +204,6 @@ join:
%cmp = icmp ne ptr %phi, null
ret i1 %cmp
}
+;.
+; CHECK: [[META0]] = !{}
+;.
More information about the llvm-commits
mailing list