<div dir="ltr">Hi,<br><br><div>The documentation for llvm.dbg.declare says: "This intrinsic provides information about a local element (e.g., variable). The first argument is metadata holding the alloca for the variable. The second argument is a local variable containing a description of the variable."<div><br><div><div>However, I've found that sometimes instcombine can make the first argument not literally be an alloca for the variable. It can be a bitcast. Is there meant to be an exception for bitcasts (can be multiple layers of casts), or am I reading the documentation too strictly?</div></div><div><br></div><div><br></div><div>Example:</div><div><br></div><div><pre style="color:rgb(0,0,0)">opt -instcombine smaller2.ll -S -o - 2>&1 | grep "llvm.dbg.declare\|tmpcast" (git)-[master]
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
%tmpcast = bitcast i64* %png_signature to [8 x i8]*, !dbg !13
call void @llvm.dbg.declare(metadata [8 x i8]* %tmpcast, metadata !14, metadata !16), !dbg !17
%arrayidx10 = getelementptr inbounds [8 x i8], [8 x i8]* %tmpcast, i32 0, i32 %start, !dbg !18</pre></div><div><pre style="color:rgb(0,0,0)"><span style="font-family:arial,sans-serif"><br></span></pre><pre style="color:rgb(0,0,0)"><span style="font-family:arial,sans-serif">===== Original smaller2.ll =====</span><br></pre></div><div><pre style="color:rgb(0,0,0)">; ModuleID = 'smaller2.ll'
target datalayout = "e-p:32:32-i64:64-n32"
target triple = "le32-unknown-nacl"
@png_sig_cmp.png_signature = external hidden unnamed_addr constant [8 x i8], align 1
; Function Attrs: nounwind
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1) #0
declare i32 @memcmp(i8*, i8*, i32)
; Function Attrs: nounwind readnone
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
define hidden i32 @png_sig_cmp(i32 %start, i32 %x, i8* %ptr) {
entry:
%png_signature = alloca [8 x i8], align 1
call void @llvm.dbg.declare(metadata [8 x i8]* %png_signature, metadata !13, metadata !15), !dbg !16
%0 = bitcast [8 x i8]* %png_signature to i8*, !dbg !16
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @png_sig_cmp.png_signature, i32 0, i32 0), i32 8, i32 1, i1 false), !dbg !17
%arrayidx10 = getelementptr inbounds [8 x i8], [8 x i8]* %png_signature, i32 0, i32 %start, !dbg !18
%call = call i32 @memcmp(i8* %ptr, i8* %arrayidx10, i32 %x), !dbg !19
ret i32 %call
}
attributes #0 = { nounwind }
attributes #1 = { nounwind readnone }
!llvm.ident = !{!0}
!<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.dbg.cu&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=VkMIiPta_HGyqWE41Q3EB2OAu0qYCbQ882YsXHwRcDg&s=GrgD4B7jP_9w96c9ORVMk15iPnUi9R542aiCwyy8b2Q&e=">llvm.dbg.cu</a> = !{!1}
!llvm.module.flags = !{!11, !12}
!0 = !{!"clang version 3.7.0"}
!1 = !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 3.7.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !3, retainedTypes: !3, subprograms: !4, globals: !3, imports: !3)
!2 = !DIFile(filename: "foo.c", directory: "/s/llvm/cmakebuild")
!3 = !{}
!4 = !{!5}
!5 = !DISubprogram(name: "png_sig_cmp", scope: !2, file: !2, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32, i32, i8*)* @png_sig_cmp, variables: !3)
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !8, !8, !9}
!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, align: 32)
!10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
!11 = !{i32 2, !"Dwarf Version", i32 4}
!12 = !{i32 2, !"Debug Info Version", i32 3}
!13 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "png_signature", scope: !5, file: !2, line: 2, type: !14)
!14 = !DIBasicType(name: "long long unsigned int", size: 64, align: 64, encoding: DW_ATE_unsigned)
!15 = !DIExpression()
!16 = !DILocation(line: 2, column: 22, scope: !5)
!17 = !DILocation(line: 3, column: 26, scope: !5)
!18 = !DILocation(line: 4, column: 30, scope: !5)
!19 = !DILocation(line: 5, column: 28, scope: !5)</pre><pre style="color:rgb(0,0,0)"><br></pre><pre style="color:rgb(0,0,0)">=====</pre>In summary, I'm wondering if the argument should strictly be an alloca. If that's the case then instcombine's PromoteCastOfAllocation's use of RAUW should be aware of llvm.dbg.declare (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_InstCombineCasts-5F8cpp-5Fsource.html-23l00148&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=VkMIiPta_HGyqWE41Q3EB2OAu0qYCbQ882YsXHwRcDg&s=sIRHYFce7Q7Dal_51_RNeQDKtdOqjzBYe2Vb29p2eGQ&e=">http://llvm.org/docs/doxygen/html/InstCombineCasts_8cpp_source.html#l00148</a>). Not sure if there are other transform passes that need to be aware too.</div><div><br></div><div>Or should I read the docs more loosely (or should the docs be clarified)?</div><div><br></div><div>Thanks,</div><div>Jan</div><div><br></div></div></div></div>