[DSE,MSSA] Add use of alloca, to guard against removal in the future.
authorFlorian Hahn <flo@fhahn.com>
Wed, 15 Apr 2020 14:21:30 +0000 (15:21 +0100)
committerFlorian Hahn <flo@fhahn.com>
Wed, 15 Apr 2020 14:23:43 +0000 (15:23 +0100)
Currently the alloca does not escape and all stores and the memset can
be removed. Adding a use of the alloca ensures not all stores are
eliminated.

llvm/test/Transforms/DeadStoreElimination/MSSA/memset-missing-debugloc.ll

index 11d155c..80db7f5 100644 (file)
@@ -4,6 +4,7 @@
 ; RUN: opt -S -march=native -dse -enable-dse-memoryssa < %s| FileCheck %s
 ; CHECK: bitcast [5 x i64]* %{{[a-zA-Z_][a-zA-Z0-9_]*}} to i8*, !dbg
 ; CHECK-NEXT: %{{[0-9]+}} = getelementptr inbounds i8, i8* %0, i64 32, !dbg ![[DBG:[0-9]+]]
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 16 %1, i8 0, i64 8, i1 false), !dbg ![[DBG:[0-9]+]]
 ; CHECK: ![[DBG]] = !DILocation(line: 2,
 
 ; The test IR is generated by running:
@@ -21,6 +22,8 @@
 ; }
 
 
+declare void @use([5 x i64]*)
+
 define dso_local i32 @_Z1av() !dbg !7 {
 entry:
   %retval = alloca i32, align 4
@@ -37,6 +40,7 @@ entry:
   store i64 2, i64* %4, align 16, !dbg !16
   %5 = getelementptr inbounds [5 x i64], [5 x i64]* %1, i32 0, i32 3, !dbg !16
   store i64 2, i64* %5, align 8, !dbg !16
+  call void @use([5 x i64]* %b)
   %call = call i32 @_Z1av(), !dbg !17
   %tobool = icmp ne i32 %call, 0, !dbg !17
   br i1 %tobool, label %if.then, label %if.end, !dbg !19