From 771c46ad291ce4c2265782c8a89a6771055c65d8 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 27 Jun 2022 16:36:10 +0200 Subject: [PATCH] [GlobalOpt] Add tests for memset with non-zero value (NFC) --- llvm/test/Transforms/GlobalOpt/ctor-memset.ll | 38 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/llvm/test/Transforms/GlobalOpt/ctor-memset.ll b/llvm/test/Transforms/GlobalOpt/ctor-memset.ll index 74d93a9..79ba25f 100644 --- a/llvm/test/Transforms/GlobalOpt/ctor-memset.ll +++ b/llvm/test/Transforms/GlobalOpt/ctor-memset.ll @@ -1,27 +1,32 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals ; RUN: opt -S -globalopt < %s | FileCheck %s -@llvm.global_ctors = appending global [6 x { i32, ptr, ptr }] [ +@llvm.global_ctors = appending global [8 x { i32, ptr, ptr }] [ { i32, ptr, ptr } { i32 65535, ptr @ctor0, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @ctor1, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @ctor2, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @ctor3, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @ctor4, ptr null }, - { i32, ptr, ptr } { i32 65535, ptr @ctor5, ptr null } + { i32, ptr, ptr } { i32 65535, ptr @ctor5, ptr null }, + { i32, ptr, ptr } { i32 65535, ptr @ctor6, ptr null }, + { i32, ptr, ptr } { i32 65535, ptr @ctor7, ptr null } ] ;. -; CHECK: @[[LLVM_GLOBAL_CTORS:[a-zA-Z0-9_$"\\.-]+]] = appending global [0 x { i32, ptr, ptr }] zeroinitializer +; CHECK: @[[LLVM_GLOBAL_CTORS:[a-zA-Z0-9_$"\\.-]+]] = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @ctor6, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @ctor7, ptr null }] ; CHECK: @[[G0:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } zeroinitializer ; CHECK: @[[G1:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32, i32 } { i32 0, i32 0, i32 1 } ; CHECK: @[[G2:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32, i32 } { i32 1, i32 0, i32 0 } ; CHECK: @[[G3:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 0, i32 1 } ; CHECK: @[[G4:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 0, i32 undef } ; CHECK: @[[G5:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i16, i32 } { i16 0, i32 1 } +; CHECK: @[[G6:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 -1, i32 -1 } +; CHECK: @[[G7:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 -1, i32 1 } ;. ; memset of all-zero global @g0 = global { i32, i32 } zeroinitializer + define internal void @ctor0() { call void @llvm.memset.p0.i64(ptr @g0, i8 0, i64 8, i1 false) ret void @@ -67,4 +72,31 @@ define internal void @ctor5() { ret void } +; memset of non-zero value (matching initializer) +@g6 = global { i32, i32 } { i32 -1, i32 -1 } + +define internal void @ctor6() { +; CHECK-LABEL: @ctor6( +; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr @g6, i8 -1, i64 8, i1 false) +; CHECK-NEXT: ret void +; + call void @llvm.memset.p0.i64(ptr @g6, i8 -1, i64 8, i1 false) + ret void +} + +; memset of non-zero value (not matching initializer) +@g7 = global { i32, i32 } { i32 -1, i32 1 } + +define internal void @ctor7() { +; CHECK-LABEL: @ctor7( +; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr @g7, i8 -1, i64 8, i1 false) +; CHECK-NEXT: ret void +; + call void @llvm.memset.p0.i64(ptr @g7, i8 -1, i64 8, i1 false) + ret void +} + declare void @llvm.memset.p0.i64(ptr, i8, i64, i1) +;. +; CHECK: attributes #[[ATTR0:[0-9]+]] = { argmemonly nofree nounwind willreturn writeonly } +;. -- 2.7.4