[llvm] 81af344 - [Mem2Reg] Add test for uninitialized nonnull loads (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 12 03:42:30 PDT 2022
Author: Nikita Popov
Date: 2022-07-12T12:42:23+02:00
New Revision: 81af34402d422c7bb5267be2ef73c9a863b8c354
URL: https://github.com/llvm/llvm-project/commit/81af34402d422c7bb5267be2ef73c9a863b8c354
DIFF: https://github.com/llvm/llvm-project/commit/81af34402d422c7bb5267be2ef73c9a863b8c354.diff
LOG: [Mem2Reg] Add test for uninitialized nonnull loads (NFC)
This shows a difference in behavior between the single block and
the multi block case.
Added:
Modified:
llvm/test/Transforms/Mem2Reg/preserve-nonnull-load-metadata.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/Mem2Reg/preserve-nonnull-load-metadata.ll b/llvm/test/Transforms/Mem2Reg/preserve-nonnull-load-metadata.ll
index 5a8f0e8c93f97..cabe06130292c 100644
--- a/llvm/test/Transforms/Mem2Reg/preserve-nonnull-load-metadata.ll
+++ b/llvm/test/Transforms/Mem2Reg/preserve-nonnull-load-metadata.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=mem2reg -S | FileCheck %s
; This tests that mem2reg preserves the !nonnull metadata on loads
@@ -5,11 +6,13 @@
; Check the case where the alloca in question has a single store.
define float* @single_store(float** %arg) {
-; CHECK-LABEL: define float* @single_store
-; CHECK: %arg.load = load float*, float** %arg, align 8
-; CHECK: [[ASSUME:%(.*)]] = icmp ne float* %arg.load, null
-; CHECK: call void @llvm.assume(i1 {{.*}}[[ASSUME]])
-; CHECK: ret float* %arg.load
+; CHECK-LABEL: @single_store(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ARG_LOAD:%.*]] = load float*, float** [[ARG:%.*]], align 8
+; CHECK-NEXT: [[TMP0:%.*]] = icmp ne float* [[ARG_LOAD]], null
+; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
+; CHECK-NEXT: ret float* [[ARG_LOAD]]
+;
entry:
%buf = alloca float*
%arg.load = load float*, float** %arg, align 8
@@ -21,11 +24,13 @@ entry:
; Check the case where the alloca in question has more than one
; store but still within one basic block.
define float* @single_block(float** %arg) {
-; CHECK-LABEL: define float* @single_block
-; CHECK: %arg.load = load float*, float** %arg, align 8
-; CHECK: [[ASSUME:%(.*)]] = icmp ne float* %arg.load, null
-; CHECK: call void @llvm.assume(i1 {{.*}}[[ASSUME]])
-; CHECK: ret float* %arg.load
+; CHECK-LABEL: @single_block(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ARG_LOAD:%.*]] = load float*, float** [[ARG:%.*]], align 8
+; CHECK-NEXT: [[TMP0:%.*]] = icmp ne float* [[ARG_LOAD]], null
+; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
+; CHECK-NEXT: ret float* [[ARG_LOAD]]
+;
entry:
%buf = alloca float*
%arg.load = load float*, float** %arg, align 8
@@ -38,14 +43,15 @@ entry:
; Check the case where the alloca in question has more than one
; store and also reads ands writes in multiple blocks.
define float* @multi_block(float** %arg) {
-; CHECK-LABEL: define float* @multi_block
-; CHECK-LABEL: entry:
-; CHECK: %arg.load = load float*, float** %arg, align 8
-; CHECK: br label %next
-; CHECK-LABEL: next:
-; CHECK: [[ASSUME:%(.*)]] = icmp ne float* %arg.load, null
-; CHECK: call void @llvm.assume(i1 {{.*}}[[ASSUME]])
-; CHECK: ret float* %arg.load
+; CHECK-LABEL: @multi_block(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ARG_LOAD:%.*]] = load float*, float** [[ARG:%.*]], align 8
+; CHECK-NEXT: br label [[NEXT:%.*]]
+; CHECK: next:
+; CHECK-NEXT: [[TMP0:%.*]] = icmp ne float* [[ARG_LOAD]], null
+; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
+; CHECK-NEXT: ret float* [[ARG_LOAD]]
+;
entry:
%buf = alloca float*
%arg.load = load float*, float** %arg, align 8
@@ -60,16 +66,16 @@ next:
; Check that we don't add an assume if it's not
; necessary i.e. the value is already implied to be nonnull
define float* @no_assume(float** %arg) {
-; CHECK-LABEL: define float* @no_assume
-; CHECK-LABEL: entry:
-; CHECK: %arg.load = load float*, float** %arg, align 8
-; CHECK: %cn = icmp ne float* %arg.load, null
-; CHECK: br i1 %cn, label %next, label %fin
-; CHECK-LABEL: next:
-; CHECK-NOT: call void @llvm.assume
-; CHECK: ret float* %arg.load
-; CHECK-LABEL: fin:
-; CHECK: ret float* null
+; CHECK-LABEL: @no_assume(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[ARG_LOAD:%.*]] = load float*, float** [[ARG:%.*]], align 8
+; CHECK-NEXT: [[CN:%.*]] = icmp ne float* [[ARG_LOAD]], null
+; CHECK-NEXT: br i1 [[CN]], label [[NEXT:%.*]], label [[FIN:%.*]]
+; CHECK: next:
+; CHECK-NEXT: ret float* [[ARG_LOAD]]
+; CHECK: fin:
+; CHECK-NEXT: ret float* null
+;
entry:
%buf = alloca float*
%arg.load = load float*, float** %arg, align 8
@@ -86,4 +92,41 @@ fin:
ret float* null
}
+define float* @no_store_single_load() {
+; CHECK-LABEL: @no_store_single_load(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret float* undef
+;
+entry:
+ %buf = alloca float*
+ %buf.load = load float*, float **%buf, !nonnull !0
+ ret float* %buf.load
+}
+
+define float* @no_store_multiple_loads(i1 %c) {
+; CHECK-LABEL: @no_store_multiple_loads(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: [[TMP0:%.*]] = icmp ne float* undef, null
+; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
+; CHECK-NEXT: ret float* undef
+; CHECK: else:
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ne float* undef, null
+; CHECK-NEXT: call void @llvm.assume(i1 [[TMP1]])
+; CHECK-NEXT: ret float* undef
+;
+entry:
+ %buf = alloca float*
+ br i1 %c, label %if, label %else
+
+if:
+ %buf.load = load float*, float **%buf, !nonnull !0
+ ret float* %buf.load
+
+ else:
+ %buf.load2 = load float*, float **%buf, !nonnull !0
+ ret float* %buf.load2
+}
+
!0 = !{}
More information about the llvm-commits
mailing list