[Remarks] Look through inttoptr/ptrtoint for -ftrivial-auto-var-init remarks.
authorJon Roelofs <jonathan_roelofs@apple.com>
Mon, 24 May 2021 16:19:31 +0000 (09:19 -0700)
committerJon Roelofs <jonathan_roelofs@apple.com>
Mon, 24 May 2021 16:23:22 +0000 (09:23 -0700)
The crasher is a related problem that @aemerson found broke speck2k6/403.gcc
when I landed https://reviews.llvm.org/D102452. It has been reduced & modified
to reproduce without that patch.

Differential revision: https://reviews.llvm.org/D102935

llvm/lib/Transforms/Utils/AutoInitRemark.cpp
llvm/test/Transforms/Util/trivial-auto-var-init-crash-20210521.ll [new file with mode: 0644]
llvm/test/Transforms/Util/trivial-auto-var-init-store.ll

index 97401a7..209f131 100644 (file)
@@ -184,8 +184,8 @@ void AutoInitRemark::inspectVariable(const Value *V,
 
 void AutoInitRemark::inspectDst(Value *Dst, OptimizationRemarkMissed &R) {
   // Find if Dst is a known variable we can give more information on.
-  SmallVector<const Value *, 2> Objects;
-  getUnderlyingObjects(Dst, Objects);
+  SmallVector<Value *, 2> Objects;
+  getUnderlyingObjectsForCodeGen(Dst, Objects);
   SmallVector<VariableInfo, 2> VIs;
   for (const Value *V : Objects)
     inspectVariable(V, VIs);
diff --git a/llvm/test/Transforms/Util/trivial-auto-var-init-crash-20210521.ll b/llvm/test/Transforms/Util/trivial-auto-var-init-crash-20210521.ll
new file mode 100644 (file)
index 0000000..c19352f
--- /dev/null
@@ -0,0 +1,70 @@
+; RUN: opt < %s -annotation-remarks -pass-remarks-missed=annotation-remarks -S -o /dev/null 2>&1 | FileCheck %s
+
+; ModuleID = 'bugpoint-reduced-simplified.bc'
+source_filename = "test.ll"
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+target triple = "arm64-apple-ios14.4.0"
+
+%struct.frop = type { i8* }
+
+; Function Attrs: argmemonly nofree nosync nounwind willreturn
+declare void @llvm.memset.p0i8.i64(i8* noalias nocapture writeonly, i8, i64, i1 immarg) #0
+
+define void @spam() local_unnamed_addr #1 !dbg !3 {
+bb:
+  call void @llvm.dbg.value(metadata %struct.frop* null, metadata !21, metadata !DIExpression()) #3, !dbg !28
+  %tmp = getelementptr inbounds %struct.frop, %struct.frop* null, i64 0, i32 0
+  %tmp1 = bitcast i8** %tmp to i8*
+
+; CHECK: remark: :1:0: Call to memset inserted by -ftrivial-auto-var-init. Memory operation size: 0 bytes.
+  tail call void @llvm.memset.p0i8.i64(i8* %tmp1, i8 0, i64 0, i1 false), !annotation !33, !dbg !28
+  ret void
+}
+
+; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #2
+
+attributes #0 = { argmemonly nofree nosync nounwind willreturn }
+attributes #1 = { "target-features"="+aes,+crypto,+fp-armv8,+neon,+sha2,+zcm,+zcz" }
+attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
+attributes #3 = { nounwind }
+
+!llvm.module.flags = !{!0}
+!llvm.dbg.cu = !{!1}
+
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
+!2 = !DIFile(filename: "frop.c", directory: "frop")
+!3 = distinct !DISubprogram(scope: !4, file: !4, line: 1, type: !5, scopeLine: 2167, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !19)
+!4 = !DIFile(filename: "", directory: "frop")
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIDerivedType(tag: DW_TAG_typedef, file: !4, line: 1, baseType: !8)
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
+!9 = distinct !DICompositeType(tag: DW_TAG_union_type, file: !4, line: 1, size: 1664, elements: !10)
+!10 = !{!11}
+!11 = !DIDerivedType(tag: DW_TAG_member, scope: !12, file: !4, line: 1, baseType: !16, size: 192)
+!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !4, line: 1, size: 832, elements: !13)
+!13 = !{!14}
+!14 = !DIDerivedType(tag: DW_TAG_member, scope: !12, file: !4, line: 1, baseType: !15, size: 448)
+!15 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !4, line: 1, size: 448, elements: !10)
+!16 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !4, line: 1, size: 192, elements: !17)
+!17 = !{!18}
+!18 = !DIDerivedType(tag: DW_TAG_member, scope: !12, file: !4, line: 1, baseType: !7, size: 64)
+!19 = !{!20}
+!20 = !DILocalVariable(arg: 1, scope: !3, file: !4, line: 1, type: !7)
+!21 = !DILocalVariable(arg: 2, scope: !22, file: !4, line: 1, type: !7)
+!22 = distinct !DISubprogram(scope: !4, file: !4, line: 1, type: !23, scopeLine: 1381, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !26)
+!23 = !DISubroutineType(types: !24)
+!24 = !{!25}
+!25 = !DIBasicType(size: 32, encoding: DW_ATE_signed)
+!26 = !{!27}
+!27 = !DILocalVariable(arg: 1, scope: !22, file: !4, line: 1, type: !7)
+!28 = !DILocation(line: 1, scope: !22, inlinedAt: !29)
+!29 = distinct !DILocation(line: 1, scope: !30)
+!30 = distinct !DILexicalBlock(scope: !31, file: !4, line: 1)
+!31 = distinct !DILexicalBlock(scope: !32, file: !4, line: 1)
+!32 = distinct !DILexicalBlock(scope: !3, file: !4, line: 1)
+
+
+!33 = !{ !"auto-init" }
index 2286d00..a80c43d 100644 (file)
@@ -116,6 +116,19 @@ define void @store_alloca_gep() {
   ret void
 }
 
+; Emit a remark that reports a store to an alloca through a GEP, with ptrtoint+inttoptr in the way.
+define void @store_alloca_gep_inttoptr() {
+; CHECK-NEXT: Store inserted by -ftrivial-auto-var-init.
+; CHECK-NEXT: Store size: 4 bytes.
+; CHECK-NEXT: Variables: dst (4 bytes).
+  %dst = alloca i32
+  %gep = getelementptr i32, i32* %dst, i32 0
+  %p2i = ptrtoint i32* %gep to i64
+  %i2p = inttoptr i64 %p2i to i32*
+  store i32 0, i32* %i2p, !annotation !0, !dbg !DILocation(scope: !4)
+  ret void
+}
+
 ; Emit a remark that reports a store to an alloca through a GEP in an array.
 define void @store_alloca_gep_array() {
 ; CHECK-NEXT: Store inserted by -ftrivial-auto-var-init.