[llvm] r333274 - [MustExecute] Fix a debug invariant issue in isGuaranteedToExecute()

David Stenberg via llvm-commits llvm-commits at lists.llvm.org
Fri May 25 06:02:59 PDT 2018


Author: dstenb
Date: Fri May 25 06:02:59 2018
New Revision: 333274

URL: http://llvm.org/viewvc/llvm-project?rev=333274&view=rev
Log:
[MustExecute] Fix a debug invariant issue in isGuaranteedToExecute()

Summary:
Look past debug intrinsics when querying whether an instruction is the
first instruction in the header block. The commit includes a reproducer
for a case where LICM would not hoist an instruction, due to the presence
of the intrinsic.

A caveat with this commit is that the check will not work properly if
the instruction at hand is a debug intrinsic. I assume that no one
depends on isGuaranteedToExecute() to return true for debug intrinsics
for these cases (and that this might be an indication of another debug
invariant issue), so I thought that it was not worth adding that extra
bit of complexity.

Reviewers: reames, anna

Reviewed By: anna

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D47197

Added:
    llvm/trunk/test/Transforms/LICM/hoist-debuginvariant.ll
Modified:
    llvm/trunk/lib/Analysis/MustExecute.cpp

Modified: llvm/trunk/lib/Analysis/MustExecute.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MustExecute.cpp?rev=333274&r1=333273&r2=333274&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MustExecute.cpp (original)
+++ llvm/trunk/lib/Analysis/MustExecute.cpp Fri May 25 06:02:59 2018
@@ -117,7 +117,7 @@ bool llvm::isGuaranteedToExecute(const I
     // exit.  At the moment, we use a (cheap) hack for the common case where
     // the instruction of interest is the first one in the block.
     return !SafetyInfo->HeaderMayThrow ||
-      Inst.getParent()->getFirstNonPHI() == &Inst;
+      Inst.getParent()->getFirstNonPHIOrDbg() == &Inst;
 
   // Somewhere in this loop there is an instruction which may throw and make us
   // exit the loop.

Added: llvm/trunk/test/Transforms/LICM/hoist-debuginvariant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/hoist-debuginvariant.ll?rev=333274&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LICM/hoist-debuginvariant.ll (added)
+++ llvm/trunk/test/Transforms/LICM/hoist-debuginvariant.ll Fri May 25 06:02:59 2018
@@ -0,0 +1,53 @@
+; RUN: opt < %s -licm -S | FileCheck %s
+; RUN: opt < %s -strip-debug -licm -S | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Verify that the sdiv is hoisted out of the loop
+; even in the presence of a preceding debug intrinsic.
+
+ at a = global i32 0
+ at b = global i32 0
+ at c = global i32 0
+
+define void @fn1() !dbg !6 {
+; CHECK-LABEL: @fn1(
+; CHECK-NEXT: [[_TMP2:%.*]] = load i32, i32* @a, align 4
+; CHECK-NEXT: [[_TMP3:%.*]] = load i32, i32* @b, align 4
+; CHECK-NEXT: [[_TMP4:%.*]] = sdiv i32 [[_TMP2]], [[_TMP3]]
+; CHECK-NEXT: br label [[BB3:%.*]]
+  br label %bb3
+
+bb3:                                              ; preds = %bb3, %0
+  call void @llvm.dbg.value(metadata i32* @c, metadata !10, metadata !DIExpression(DW_OP_deref)), !dbg !12
+  %_tmp2 = load i32, i32* @a, align 4
+  %_tmp3 = load i32, i32* @b, align 4
+  %_tmp4 = sdiv i32 %_tmp2, %_tmp3
+  store i32 %_tmp4, i32* @c, align 4
+  %_tmp6 = load volatile i32, i32* @c, align 4
+  br label %bb3
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.value(metadata, metadata, metadata) #0
+
+attributes #0 = { nounwind readnone speculatable }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+!llvm.ident = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "foo", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2)
+!1 = !DIFile(filename: "foo.c", directory: "/")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{!"foo"}
+!6 = distinct !DISubprogram(name: "fn1", scope: !1, file: !1, line: 3, type: !7, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: false, unit: !0, retainedNodes: !2)
+!7 = !DISubroutineType(types: !8)
+!8 = !{!9}
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !DILocalVariable(name: "f", scope: !11, line: 5, type: !9)
+!11 = distinct !DILexicalBlock(scope: !6, file: !1, line: 4, column: 12)
+!12 = !DILocation(line: 5, column: 9, scope: !11)




More information about the llvm-commits mailing list