[llvm] r334317 - [InstCombine] Skip dbg.value(s) when looking at stack{save, restore}.

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 8 16:02:43 PDT 2018


Hi Davide,

A question inline --

> On Jun 8, 2018, at 1:42 PM, Davide Italiano via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Author: davide
> Date: Fri Jun  8 13:42:36 2018
> New Revision: 334317
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=334317&view=rev
> Log:
> [InstCombine] Skip dbg.value(s) when looking at stack{save,restore}.
> 
> Fixes PR37713.
> 
> Added:
>    llvm/trunk/test/Transforms/InstCombine/stacksave-debuginfo.ll
> Modified:
>    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=334317&r1=334316&r2=334317&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Fri Jun  8 13:42:36 2018
> @@ -3521,8 +3521,15 @@ Instruction *InstCombiner::visitCallInst
>     // happen when variable allocas are DCE'd.
>     if (IntrinsicInst *SS = dyn_cast<IntrinsicInst>(II->getArgOperand(0))) {
>       if (SS->getIntrinsicID() == Intrinsic::stacksave) {
> -        if (&*++SS->getIterator() == II)
> +        // Skip over debug info instructions.
> +        // FIXME: This should be an utility in Instruction.h
> +        auto It = SS->getIterator();
> +        It++;
> +        while (isa<DbgInfoIntrinsic>(*It))

^ Can you dereference the sentinel node in this while loop's condition?

vedant

> +          It++;
> +        if (&*It == II) {
>           return eraseInstFromFunction(CI);
> +        }
>       }
>     }
> 
> 
> Added: llvm/trunk/test/Transforms/InstCombine/stacksave-debuginfo.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/stacksave-debuginfo.ll?rev=334317&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/stacksave-debuginfo.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/stacksave-debuginfo.ll Fri Jun  8 13:42:36 2018
> @@ -0,0 +1,47 @@
> +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
> +; dbg.value instrinsics should not affect peephole combining of stacksave/stackrestore.
> +; PR37713
> +; RUN: opt -instcombine %s -S | FileCheck %s
> +
> +declare i8* @llvm.stacksave() #0
> +declare void @llvm.stackrestore(i8*) #0
> +
> +define i32* @test1(i32 %P) !dbg !6 {
> +; CHECK-LABEL: @test1(
> +; CHECK-NEXT:    [[TMP1:%.*]] = zext i32 [[P:%.*]] to i64, !dbg !12
> +; CHECK-NEXT:    [[A:%.*]] = alloca i32, i64 [[TMP1]], align 4, !dbg !12
> +; CHECK-NEXT:    call void @llvm.dbg.value(metadata i32* [[A]], metadata !11, metadata !DIExpression()), !dbg !12
> +; CHECK-NEXT:    ret i32* [[A]], !dbg !13
> +;
> +  %tmp = call i8* @llvm.stacksave(), !dbg !12
> +  call void @llvm.dbg.value(metadata i8* %tmp, metadata !9, metadata !DIExpression()), !dbg !12
> +  call void @llvm.stackrestore(i8* %tmp), !dbg !13
> +  %A = alloca i32, i32 %P, !dbg !14
> +  call void @llvm.dbg.value(metadata i32* %A, metadata !11, metadata !DIExpression()), !dbg !14
> +  ret i32* %A, !dbg !15
> +}
> +
> +declare void @llvm.dbg.value(metadata, metadata, metadata) #1
> +attributes #0 = { nounwind }
> +attributes #1 = { nounwind readnone speculatable }
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.debugify = !{!3, !4}
> +!llvm.module.flags = !{!5}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
> +!1 = !DIFile(filename: "patatino.ll", directory: "/")
> +!2 = !{}
> +!3 = !{i32 4}
> +!4 = !{i32 2}
> +!5 = !{i32 2, !"Debug Info Version", i32 3}
> +!6 = distinct !DISubprogram(name: "test1", linkageName: "test1", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8)
> +!7 = !DISubroutineType(types: !2)
> +!8 = !{!9, !11}
> +!9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
> +!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
> +!11 = !DILocalVariable(name: "2", scope: !6, file: !1, line: 3, type: !10)
> +!12 = !DILocation(line: 1, column: 1, scope: !6)
> +!13 = !DILocation(line: 2, column: 1, scope: !6)
> +!14 = !DILocation(line: 3, column: 1, scope: !6)
> +!15 = !DILocation(line: 4, column: 1, scope: !6)
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list