From 2ead232626a5028d50c8ed21d17f3a0f0946f89b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 3 Apr 2023 15:40:56 +0200 Subject: [PATCH] [EarlyCSE] Add metadata preservation tests (NFC) --- llvm/test/Transforms/EarlyCSE/flags.ll | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/llvm/test/Transforms/EarlyCSE/flags.ll b/llvm/test/Transforms/EarlyCSE/flags.ll index 82fba148..6134c81 100644 --- a/llvm/test/Transforms/EarlyCSE/flags.ll +++ b/llvm/test/Transforms/EarlyCSE/flags.ll @@ -3,6 +3,7 @@ ; RUN: opt -passes='early-cse' -S < %s | FileCheck %s declare void @use(i1) +declare void @use.ptr(ptr) memory(read) define void @test1(float %x, float %y) { ; CHECK-LABEL: @test1( @@ -47,3 +48,45 @@ define void @test_inbounds_program_not_ub_if_first_gep_poison(ptr %ptr, i64 %n) call void @use.i8(ptr %add.ptr.2) ret void } + +define void @load_both_nonnull(ptr %p) { +; CHECK-LABEL: @load_both_nonnull( +; CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull !0 +; CHECK-NEXT: call void @use.ptr(ptr [[V1]]) +; CHECK-NEXT: call void @use.ptr(ptr [[V1]]) +; CHECK-NEXT: ret void +; + %v1 = load ptr, ptr %p, !nonnull !{} + call void @use.ptr(ptr %v1) + %v2 = load ptr, ptr %p, !nonnull !{} + call void @use.ptr(ptr %v2) + ret void +} + +define void @load_first_nonnull(ptr %p) { +; CHECK-LABEL: @load_first_nonnull( +; CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull !0 +; CHECK-NEXT: call void @use.ptr(ptr [[V1]]) +; CHECK-NEXT: call void @use.ptr(ptr [[V1]]) +; CHECK-NEXT: ret void +; + %v1 = load ptr, ptr %p, !nonnull !{} + call void @use.ptr(ptr %v1) + %v2 = load ptr, ptr %p + call void @use.ptr(ptr %v2) + ret void +} + +define void @load_first_nonnull_noundef(ptr %p) { +; CHECK-LABEL: @load_first_nonnull_noundef( +; CHECK-NEXT: [[V1:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull !0, !noundef !0 +; CHECK-NEXT: call void @use.ptr(ptr [[V1]]) +; CHECK-NEXT: call void @use.ptr(ptr [[V1]]) +; CHECK-NEXT: ret void +; + %v1 = load ptr, ptr %p, !nonnull !{}, !noundef !{} + call void @use.ptr(ptr %v1) + %v2 = load ptr, ptr %p + call void @use.ptr(ptr %v2) + ret void +} -- 2.7.4