[llvm] r327092 - LowerDbgDeclare: ignore dbg.declares for allocas with volatile access

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 12 11:24:49 PDT 2018


What if only some of the loads/stores are volatile?

int i = x;
*((volatile unsigned*)&i) = 3;

Then maybe LLVM could still optimize away a bunch of the use of 'i' & so
describing the alloca may be worse than describing the
reads/writes/notional value?

On Thu, Mar 8, 2018 at 4:47 PM Adrian Prantl via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: adrian
> Date: Thu Mar  8 16:45:04 2018
> New Revision: 327092
>
> URL: http://llvm.org/viewvc/llvm-project?rev=327092&view=rev
> Log:
> LowerDbgDeclare: ignore dbg.declares for allocas with volatile access
>
> There is no point in lowering a dbg.declare describing an alloca that
> has volatile loads or stores as users, since the alloca cannot be
> elided. Lowering the dbg.declare will result in larger debug info that
> may also have worse coverage than just describing the alloca.
>
> rdar://problem/34496278
>
> Added:
>     llvm/trunk/test/DebugInfo/Generic/volatile-alloca.ll
> Modified:
>     llvm/trunk/lib/Transforms/Utils/Local.cpp
>     llvm/trunk/test/Transforms/Util/simplify-dbg-declare-load.ll
>
> Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=327092&r1=327091&r2=327092&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/Local.cpp Thu Mar  8 16:45:04 2018
> @@ -1322,25 +1322,36 @@ bool llvm::LowerDbgDeclare(Function &F)
>      // stored on the stack, while the dbg.declare can only describe
>      // the stack slot (and at a lexical-scope granularity). Later
>      // passes will attempt to elide the stack slot.
> -    if (AI && !isArray(AI)) {
> -      for (auto &AIUse : AI->uses()) {
> -        User *U = AIUse.getUser();
> -        if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
> -          if (AIUse.getOperandNo() == 1)
> -            ConvertDebugDeclareToDebugValue(DDI, SI, DIB);
> -        } else if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
> -          ConvertDebugDeclareToDebugValue(DDI, LI, DIB);
> -        } else if (CallInst *CI = dyn_cast<CallInst>(U)) {
> -          // This is a call by-value or some other instruction that
> -          // takes a pointer to the variable. Insert a *value*
> -          // intrinsic that describes the alloca.
> -          DIB.insertDbgValueIntrinsic(AI, DDI->getVariable(),
> -                                      DDI->getExpression(),
> DDI->getDebugLoc(),
> -                                      CI);
> -        }
> +    if (!AI || isArray(AI))
> +      continue;
> +
> +    // A volatile load/store means that the alloca can't be elided anyway.
> +    if (llvm::any_of(AI->users(), [](User *U) -> bool {
> +          if (LoadInst *LI = dyn_cast<LoadInst>(U))
> +            return LI->isVolatile();
> +          if (StoreInst *SI = dyn_cast<StoreInst>(U))
> +            return SI->isVolatile();
> +          return false;
> +        }))
> +      continue;
> +
> +    for (auto &AIUse : AI->uses()) {
> +      User *U = AIUse.getUser();
> +      if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
> +        if (AIUse.getOperandNo() == 1)
> +          ConvertDebugDeclareToDebugValue(DDI, SI, DIB);
> +      } else if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
> +        ConvertDebugDeclareToDebugValue(DDI, LI, DIB);
> +      } else if (CallInst *CI = dyn_cast<CallInst>(U)) {
> +        // This is a call by-value or some other instruction that
> +        // takes a pointer to the variable. Insert a *value*
> +        // intrinsic that describes the alloca.
> +        DIB.insertDbgValueIntrinsic(AI, DDI->getVariable(),
> +                                    DDI->getExpression(),
> DDI->getDebugLoc(),
> +                                    CI);
>        }
> -      DDI->eraseFromParent();
>      }
> +    DDI->eraseFromParent();
>    }
>    return true;
>  }
>
> Added: llvm/trunk/test/DebugInfo/Generic/volatile-alloca.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/volatile-alloca.ll?rev=327092&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/Generic/volatile-alloca.ll (added)
> +++ llvm/trunk/test/DebugInfo/Generic/volatile-alloca.ll Thu Mar  8
> 16:45:04 2018
> @@ -0,0 +1,83 @@
> +; RUN: opt -mem2reg -instcombine %s -o - -S | FileCheck %s
> +;
> +; Test that a dbg.declare describing am alloca with volatile
> +; load/stores is not lowered into a dbg.value, since the alloca won't
> +; be elided anyway.
> +;
> +; Generated from:
> +;
> +; unsigned long long g();
> +; void h(unsigned long long);
> +; void f() {
> +;   volatile unsigned long long v = g();
> +;   if (v == 0)
> +;     g();
> +;   h(v);
> +; }
> +
> +; CHECK: alloca i64
> +; CHECK-NOT: call void @llvm.dbg.value
> +; CHECK: call void @llvm.dbg.declare
> +; CHECK-NOT: call void @llvm.dbg.value
> +
> +source_filename = "volatile.c"
> +
> +; Function Attrs: nounwind optsize ssp uwtable
> +define void @f() local_unnamed_addr #0 !dbg !8 {
> +  %1 = alloca i64, align 8
> +  %2 = bitcast i64* %1 to i8*, !dbg !15
> +  call void @llvm.lifetime.start.p0i8(i64 8, i8* %2), !dbg !15
> +  call void @llvm.dbg.declare(metadata i64* %1, metadata !12, metadata
> !DIExpression()), !dbg !15
> +  %3 = call i64 (...) @g() #4, !dbg !15
> +  store volatile i64 %3, i64* %1, align 8, !dbg !15
> +  %4 = load volatile i64, i64* %1, align 8, !dbg !15
> +  %5 = icmp eq i64 %4, 0, !dbg !15
> +  br i1 %5, label %6, label %8, !dbg !15
> +
> +; <label>:6:                                      ; preds = %0
> +  %7 = call i64 (...) @g() #4, !dbg !15
> +  br label %8, !dbg !15
> +
> +; <label>:8:                                      ; preds = %6, %0
> +  %9 = load volatile i64, i64* %1, align 8, !dbg !15
> +  call void @h(i64 %9) #4, !dbg !15
> +  call void @llvm.lifetime.end.p0i8(i64 8, i8* %2), !dbg !15
> +  ret void, !dbg !15
> +}
> +
> +; Function Attrs: argmemonly nounwind
> +declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
> +
> +; Function Attrs: nounwind readnone speculatable
> +declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
> +
> +; Function Attrs: optsize
> +declare i64 @g(...) local_unnamed_addr #3
> +
> +; Function Attrs: optsize
> +declare void @h(i64) local_unnamed_addr #3
> +
> +; Function Attrs: argmemonly nounwind
> +declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
> +
> +attributes #0 = { nounwind optsize ssp uwtable }
> +attributes #1 = { argmemonly nounwind }
> +attributes #2 = { nounwind readnone speculatable }
> +attributes #3 = { optsize }
> +attributes #4 = { optsize }
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!3, !4}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer:
> "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
> +!1 = !DIFile(filename: "volatile.c", directory: "/")
> +!3 = !{i32 2, !"Dwarf Version", i32 4}
> +!4 = !{i32 2, !"Debug Info Version", i32 3}
> +!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3,
> type: !9, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized:
> true, unit: !0, variables: !11)
> +!9 = !DISubroutineType(types: !10)
> +!10 = !{null}
> +!11 = !{!12}
> +!12 = !DILocalVariable(name: "v", scope: !8, file: !1, line: 4, type: !13)
> +!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !14)
> +!14 = !DIBasicType(name: "long long unsigned int", size: 64, encoding:
> DW_ATE_unsigned)
> +!15 = !DILocation(line: 4, column: 3, scope: !8)
>
> Modified: llvm/trunk/test/Transforms/Util/simplify-dbg-declare-load.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Util/simplify-dbg-declare-load.ll?rev=327092&r1=327091&r2=327092&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/Util/simplify-dbg-declare-load.ll (original)
> +++ llvm/trunk/test/Transforms/Util/simplify-dbg-declare-load.ll Thu Mar
> 8 16:45:04 2018
> @@ -13,6 +13,7 @@ declare void @llvm.dbg.value(metadata, m
>  define void @julia_fastshortest_6256() #1 {
>  top:
>    %cp = alloca %foo, align 8
> +  %sink = alloca %foo, align 8
>    call void @llvm.dbg.declare(metadata %foo* %cp, metadata !1, metadata
> !16), !dbg !17
>    br i1 undef, label %idxend, label %fail
>
> @@ -21,9 +22,10 @@ fail:
>
>  idxend:                                           ; preds = %top
>  ; CHECK-NOT: call void @llvm.dbg.value(metadata %foo* %cp,
> -  %0 = load volatile %foo, %foo* %cp, align 8
> -; CHECK: call void @llvm.dbg.value(metadata %foo %0,
> -  store volatile %foo %0, %foo* undef, align 8
> +  %0 = load %foo, %foo* %cp, align 8
> +  store volatile %foo %0, %foo *%sink, align 8
> +; CHECK: call void @llvm.dbg.value(metadata %foo %
> +  store %foo %0, %foo* undef, align 8
>    ret void
>  }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180312/e0b1fa5c/attachment-0001.html>


More information about the llvm-commits mailing list