Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3387,11 +3387,14 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
// Metadata can be dependent on the condition we are hoisting above.
// Strip all UB-implying metadata on the instruction. Drop the debug loc
// to avoid making it appear as if the condition is a constant, which would
// be misleading while debugging.
// be misleading while debugging. However, make sure to keep debug info
// for calls as inlinable function calls in a function with debug info must
// have a !dbg location.
// Similarly strip attributes that maybe dependent on condition we are
// hoisting above.
for (auto &I : make_early_inc_range(*ThenBB)) {
if (!SpeculatedStoreValue || &I != SpeculatedStore) {
if ((!SpeculatedStoreValue || &I != SpeculatedStore) &&
!isa<CallBase>(&I)) {
I.setDebugLoc(DebugLoc::getDropped());
}
I.dropUBImplyingAttrsAndMetadata();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
; RUN: opt -S -o - %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s


declare i1 @make_condition()

define i1 @specfn() readnone nounwind speculatable {
ret i1 true
}

; CHECK-LABEL: @test1(
; CHECK: call i1 @specfn(), !dbg
; CHECK: select i1
define void @test1() !dbg !6 {
start:
%cond = call i1 @make_condition(), !dbg !8
br i1 %cond, label %then, label %else, !dbg !9

then: ; preds = %start
%sres = call i1 @specfn(), !dbg !8
br label %else, !dbg !11

else: ; preds = %then, %start
%phi = phi i1 [ %cond, %start ], [ %sres, %then ], !dbg !12
ret void, !dbg !13
}

!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: "test.ll", directory: "/")
!2 = !{}
!3 = !{i32 6}
!4 = !{i32 0}
!5 = !{i32 2, !"Debug Info Version", i32 3}
!6 = distinct !DISubprogram(name: "test1", linkageName: "test1", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
!7 = !DISubroutineType(types: !2)
!8 = !DILocation(line: 1, column: 1, scope: !6)
!9 = !DILocation(line: 2, column: 1, scope: !6)
!10 = !DILocation(line: 3, column: 2, scope: !6)
!11 = !DILocation(line: 4, column: 2, scope: !6)
!12 = !DILocation(line: 5, column: 3, scope: !6)
!13 = !DILocation(line: 6, column: 3, scope: !6)
Loading