<div dir="ltr"><div dir="ltr">Hi Mikael,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 28, 2019 at 2:39 PM Mikael Holmén <<a href="mailto:mikael.holmen@ericsson.com">mikael.holmen@ericsson.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I'm happy if you do it :)<br></blockquote><div><br></div><div>I am happy to prepare the patch.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
THe big comment in llvm::hoistAllInstructionsInto mentions dbg.values <br>
explicitly several times, I suppose it would be good to generalize that <br>
to talk about dbg intrinsics in general if we generalize the code.<br></blockquote><div><br></div><div>Good point. A more generalized comment is needed as well.<br></div><div><br></div><div>Thanks,</div><div>Carlos<br></div><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> On Mon, Jan 28, 2019 at 9:12 AM Mikael Holmén <br>
> <<a href="mailto:mikael.holmen@ericsson.com" target="_blank">mikael.holmen@ericsson.com</a> <mailto:<a href="mailto:mikael.holmen@ericsson.com" target="_blank">mikael.holmen@ericsson.com</a>>> wrote:<br>
> <br>
>     Hi Carlos,<br>
> <br>
>     I've stumbled on a case where the verifier complains with this change.<br>
>     With<br>
> <br>
>        opt -S -o - bbi-23595.ll -simplifycfg<br>
> <br>
>     you get<br>
> <br>
>     llvm.dbg.label intrinsic requires a !dbg attachment<br>
>         call void @llvm.dbg.label(metadata !1)<br>
>     label %entry<br>
>     i16 ()* @_Z7test_itv<br>
>     in function _Z7test_itv<br>
>     LLVM ERROR: Broken function found, compilation aborted!<br>
> <br>
>     With -print-after-all:<br>
> <br>
>     *** IR Dump After Simplify the CFG ***<br>
>     define i16 @_Z7test_itv() {<br>
>     entry:<br>
>         call void @llvm.dbg.label(metadata !1)<br>
>         %retval.0 = select i1 undef, i16 1, i16 0<br>
>         ret i16 0<br>
>     }<br>
> <br>
>     So simplifycfg has dropped the !dbg from the dbg.label, but kept the<br>
>     instruction itself.<br>
> <br>
>     Should perhaps<br>
> <br>
>     +    if (isa<DbgVariableIntrinsic>(I)) {<br>
>     +      // Remove DbgInfo Intrinsics.<br>
>     +      II = I->eraseFromParent();<br>
>     +      continue;<br>
>     +    }<br>
> <br>
>     in llvm::hoistAllInstructionsInto drop all DbgInfoIntrinsic instead of<br>
>     just DbgVariableIntrinsic ?<br>
> <br>
>     Regards,<br>
>     Mikael<br>
> <br>
> <br>
>     On 10/25/18 11:58 AM, Carlos Alberto Enciso via llvm-commits wrote:<br>
>      > Author: carlos.alberto.enciso<br>
>      > Date: Thu Oct 25 02:58:59 2018<br>
>      > New Revision: 345250<br>
>      ><br>
>      > URL: <a href="http://llvm.org/viewvc/llvm-project?rev=345250&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=345250&view=rev</a><br>
>      > Log:<br>
>      > [DebugInfo][Dexter] Unreachable line stepped onto after SimplifyCFG.<br>
>      ><br>
>      > When SimplifyCFG changes the PHI node into a select instruction,<br>
>     the debug line records becomes ambiguous. It causes the debugger to<br>
>     display unreachable source lines.<br>
>      ><br>
>      > Differential Revision: <a href="https://reviews.llvm.org/D53287" rel="noreferrer" target="_blank">https://reviews.llvm.org/D53287</a><br>
>      ><br>
>      > Added:<br>
>      >      llvm/trunk/test/CodeGen/X86/pr38762.ll<br>
>      >      llvm/trunk/test/CodeGen/X86/pr39243.ll<br>
>      > Modified:<br>
>      >      llvm/trunk/include/llvm/Transforms/Utils/Local.h<br>
>      >      llvm/trunk/lib/Transforms/Utils/Local.cpp<br>
>      >      llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp<br>
>      >      llvm/trunk/test/CodeGen/X86/pr38763.ll<br>
>      ><br>
>      > Modified: llvm/trunk/include/llvm/Transforms/Utils/Local.h<br>
>      > URL:<br>
>     <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=345250&r1=345249&r2=345250&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=345250&r1=345249&r2=345250&view=diff</a><br>
>      ><br>
>     ==============================================================================<br>
>      > --- llvm/trunk/include/llvm/Transforms/Utils/Local.h (original)<br>
>      > +++ llvm/trunk/include/llvm/Transforms/Utils/Local.h Thu Oct 25<br>
>     02:58:59 2018<br>
>      > @@ -446,6 +446,15 @@ void copyRangeMetadata(const DataLayout<br>
>      >   /// Remove the debug intrinsic instructions for the given<br>
>     instruction.<br>
>      >   void dropDebugUsers(Instruction &I);<br>
>      ><br>
>      > +/// Hoist all of the instructions in the \p IfBlock to the<br>
>     dominant block<br>
>      > +/// \p DomBlock, by moving its instructions to the insertion<br>
>     point \p InsertPt.<br>
>      > +///<br>
>      > +/// The moved instructions receive the insertion point debug<br>
>     location values<br>
>      > +/// (DILocations) and their debug intrinsic instructions<br>
>     (dbg.values) are<br>
>      > +/// removed.<br>
>      > +void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction<br>
>     *InsertPt,<br>
>      > +                              BasicBlock *BB);<br>
>      > +<br>
>      > <br>
>       //===----------------------------------------------------------------------===//<br>
>      >   //  Intrinsic pattern matching<br>
>      >   //<br>
>      ><br>
>      > Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp<br>
>      > URL:<br>
>     <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=345250&r1=345249&r2=345250&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=345250&r1=345249&r2=345250&view=diff</a><br>
>      ><br>
>     ==============================================================================<br>
>      > --- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)<br>
>      > +++ llvm/trunk/lib/Transforms/Utils/Local.cpp Thu Oct 25 02:58:59<br>
>     2018<br>
>      > @@ -2529,6 +2529,47 @@ void llvm::dropDebugUsers(Instruction &I<br>
>      >       DII->eraseFromParent();<br>
>      >   }<br>
>      ><br>
>      > +void llvm::hoistAllInstructionsInto(BasicBlock *DomBlock,<br>
>     Instruction *InsertPt,<br>
>      > +                                    BasicBlock *BB) {<br>
>      > +  // Since we are moving the instructions out of its basic<br>
>     block, we do not<br>
>      > +  // retain their original debug locations (DILocations) and<br>
>     debug intrinsic<br>
>      > +  // instructions (dbg.values).<br>
>      > +  //<br>
>      > +  // Doing so would degrade the debugging experience and<br>
>     adversely affect the<br>
>      > +  // accuracy of profiling information.<br>
>      > +  //<br>
>      > +  // Currently, when hoisting the instructions, we take the<br>
>     following actions:<br>
>      > +  // - Remove their dbg.values.<br>
>      > +  // - Set their debug locations to the values from the<br>
>     insertion point.<br>
>      > +  //<br>
>      > +  // As per PR39141 (comment #8), the more fundamental reason<br>
>     why the dbg.values<br>
>      > +  // need to be deleted, is because there will not be any<br>
>     instructions with a<br>
>      > +  // DILocation in either branch left after performing the<br>
>     transformation. We<br>
>      > +  // can only insert a dbg.value after the two branches are<br>
>     joined again.<br>
>      > +  //<br>
>      > +  // See PR38762, PR39243 for more details.<br>
>      > +  //<br>
>      > +  // TODO: Extend llvm.dbg.value to take more than one SSA Value<br>
>     (PR39141) to<br>
>      > +  // encode predicated DIExpressions that yield different<br>
>     results on different<br>
>      > +  // code paths.<br>
>      > +  for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II<br>
>     != IE;) {<br>
>      > +    Instruction *I = &*II;<br>
>      > +    I->dropUnknownNonDebugMetadata();<br>
>      > +    if (I->isUsedByMetadata())<br>
>      > +      dropDebugUsers(*I);<br>
>      > +    if (isa<DbgVariableIntrinsic>(I)) {<br>
>      > +      // Remove DbgInfo Intrinsics.<br>
>      > +      II = I->eraseFromParent();<br>
>      > +      continue;<br>
>      > +    }<br>
>      > +    I->setDebugLoc(InsertPt->getDebugLoc());<br>
>      > +    ++II;<br>
>      > +  }<br>
>      > +  DomBlock->getInstList().splice(InsertPt->getIterator(),<br>
>     BB->getInstList(),<br>
>      > +                                 BB->begin(),<br>
>      > +                               <br>
>       BB->getTerminator()->getIterator());<br>
>      > +}<br>
>      > +<br>
>      >   namespace {<br>
>      ><br>
>      >   /// A potential constituent of a bitreverse or bswap<br>
>     expression. See<br>
>      ><br>
>      > Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp<br>
>      > URL:<br>
>     <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=345250&r1=345249&r2=345250&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=345250&r1=345249&r2=345250&view=diff</a><br>
>      ><br>
>     ==============================================================================<br>
>      > --- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)<br>
>      > +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Thu Oct 25<br>
>     02:58:59 2018<br>
>      > @@ -2375,24 +2375,10 @@ static bool FoldTwoEntryPHINode(PHINode<br>
>      ><br>
>      >     // Move all 'aggressive' instructions, which are defined in the<br>
>      >     // conditional parts of the if's up to the dominating block.<br>
>      > -  if (IfBlock1) {<br>
>      > -    for (auto &I : *IfBlock1) {<br>
>      > -      I.dropUnknownNonDebugMetadata();<br>
>      > -      dropDebugUsers(I);<br>
>      > -    }<br>
>      > -    DomBlock->getInstList().splice(InsertPt->getIterator(),<br>
>      > -                                   IfBlock1->getInstList(),<br>
>     IfBlock1->begin(),<br>
>      > -                                 <br>
>       IfBlock1->getTerminator()->getIterator());<br>
>      > -  }<br>
>      > -  if (IfBlock2) {<br>
>      > -    for (auto &I : *IfBlock2) {<br>
>      > -      I.dropUnknownNonDebugMetadata();<br>
>      > -      dropDebugUsers(I);<br>
>      > -    }<br>
>      > -    DomBlock->getInstList().splice(InsertPt->getIterator(),<br>
>      > -                                   IfBlock2->getInstList(),<br>
>     IfBlock2->begin(),<br>
>      > -                                 <br>
>       IfBlock2->getTerminator()->getIterator());<br>
>      > -  }<br>
>      > +  if (IfBlock1)<br>
>      > +    hoistAllInstructionsInto(DomBlock, InsertPt, IfBlock1);<br>
>      > +  if (IfBlock2)<br>
>      > +    hoistAllInstructionsInto(DomBlock, InsertPt, IfBlock2);<br>
>      ><br>
>      >     while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {<br>
>      >       // Change the PHI node into a select instruction.<br>
>      ><br>
>      > Added: llvm/trunk/test/CodeGen/X86/pr38762.ll<br>
>      > URL:<br>
>     <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr38762.ll?rev=345250&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr38762.ll?rev=345250&view=auto</a><br>
>      ><br>
>     ==============================================================================<br>
>      > --- llvm/trunk/test/CodeGen/X86/pr38762.ll (added)<br>
>      > +++ llvm/trunk/test/CodeGen/X86/pr38762.ll Thu Oct 25 02:58:59 2018<br>
>      > @@ -0,0 +1,101 @@<br>
>      > +; RUN: opt < %s -S -simplifycfg | FileCheck %s<br>
>      > +<br>
>      > +; Note: This patch is a complement to pr38763.<br>
>      > +;<br>
>      > +; When SimplifyCFG changes the PHI node into a select<br>
>     instruction, the debug<br>
>      > +; information becomes ambiguous. It causes the debugger to<br>
>     display unreached<br>
>      > +; lines and invalid variable values.<br>
>      > +;<br>
>      > +; When in the debugger, on the line "if (read1 > 3)", and we<br>
>     step from the<br>
>      > +; 'if' condition, onto the addition, then back to the 'if'<br>
>     again, which is<br>
>      > +; misleading because that addition doesn't really "happen" (it's<br>
>     speculated).<br>
>      > +<br>
>      > +; IR generated with:<br>
>      > +; clang -S -g -gno-column-info -O2 -emit-llvm pr38762.cpp -o<br>
>     pr38762.ll -mllvm -opt-bisect-limit=10<br>
>      > +<br>
>      > +; // pr38762.cpp<br>
>      > +; int main() {<br>
>      > +;   volatile int foo = 0;<br>
>      > +;   int read1 = foo;<br>
>      > +;   int brains = foo;<br>
>      > +;<br>
>      > +;   if (read1 > 3) {<br>
>      > +;     brains *= 2;<br>
>      > +;     brains += 1;<br>
>      > +;   }<br>
>      > +;<br>
>      > +;   return brains;<br>
>      > +; }<br>
>      > +<br>
>      > +; Change the debug locations associated with the PHI nodes being<br>
>     promoted, to<br>
>      > +; the debug locations from the insertion point in the dominant<br>
>     block.<br>
>      > +<br>
>      > +; CHECK-LABEL: entry<br>
>      > +; CHECK:  %cmp = icmp sgt i32 %foo.0., 3, !dbg !14<br>
>      > +; CHECK:  %mul = shl nsw i32 %foo.0.5, 1, !dbg !16<br>
>      > +; CHECK-NOT:  call void @llvm.dbg.value(metadata i32 %mul,<br>
>     metadata !15, metadata !DIExpression()), !dbg !25<br>
>      > +; CHECK:  %add = or i32 %mul, 1, !dbg !16<br>
>      > +; CHECK-NOT:  call void @llvm.dbg.value(metadata i32 %add,<br>
>     metadata !15, metadata !DIExpression()), !dbg !25<br>
>      > +; CHECK:  %brains.0 = select i1 %cmp, i32 %add, i32 %foo.0.5,<br>
>     !dbg !16<br>
>      > +<br>
>      > +; ModuleID = 'pr38762.cpp'<br>
>      > +source_filename = "pr38762.cpp"<br>
>      > +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
>      > +target triple = "x86_64-pc-linux-gnu"<br>
>      > +<br>
>      > +; Function Attrs: norecurse nounwind uwtable<br>
>      > +define dso_local i32 @main() local_unnamed_addr #0 !dbg !7 {<br>
>      > +entry:<br>
>      > +  %foo = alloca i32, align 4<br>
>      > +  %foo.0..sroa_cast = bitcast i32* %foo to i8*<br>
>      > +  store volatile i32 0, i32* %foo, align 4<br>
>      > +  %foo.0. = load volatile i32, i32* %foo, align 4<br>
>      > +  %foo.0.5 = load volatile i32, i32* %foo, align 4<br>
>      > +  call void @llvm.dbg.value(metadata i32 %foo.0.5, metadata !15,<br>
>     metadata !DIExpression()), !dbg !25<br>
>      > +  %cmp = icmp sgt i32 %foo.0., 3, !dbg !26<br>
>      > +  br i1 %cmp, label %if.then, label %if.end, !dbg !28<br>
>      > +<br>
>      > +if.then:                                          ; preds = %entry<br>
>      > +  %mul = shl nsw i32 %foo.0.5, 1, !dbg !29<br>
>      > +  call void @llvm.dbg.value(metadata i32 %mul, metadata !15,<br>
>     metadata !DIExpression()), !dbg !25<br>
>      > +  %add = or i32 %mul, 1, !dbg !31<br>
>      > +  call void @llvm.dbg.value(metadata i32 %add, metadata !15,<br>
>     metadata !DIExpression()), !dbg !25<br>
>      > +  br label %if.end, !dbg !32<br>
>      > +<br>
>      > +if.end:                                           ; preds =<br>
>     %if.then, %entry<br>
>      > +  %brains.0 = phi i32 [ %add, %if.then ], [ %foo.0.5, %entry ],<br>
>     !dbg !33<br>
>      > +  call void @llvm.dbg.value(metadata i32 %brains.0, metadata<br>
>     !15, metadata !DIExpression()), !dbg !25<br>
>      > +  ret i32 %brains.0, !dbg !35<br>
>      > +}<br>
>      > +<br>
>      > +declare void @llvm.dbg.value(metadata, metadata, metadata) #2<br>
>      > +<br>
>      > +!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> <<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">http://llvm.dbg.cu</a>> = !{!0}<br>
>      > +!llvm.module.flags = !{!3, !4, !5}<br>
>      > +!llvm.ident = !{!6}<br>
>      > +<br>
>      > +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus,<br>
>     file: !1, producer: "clang version 8.0.0 (trunk 343753)",<br>
>     isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug,<br>
>     enums: !2, nameTableKind: None)<br>
>      > +!1 = !DIFile(filename: "pr38762.cpp", directory: ".")<br>
>      > +!2 = !{}<br>
>      > +!3 = !{i32 2, !"Dwarf Version", i32 4}<br>
>      > +!4 = !{i32 2, !"Debug Info Version", i32 3}<br>
>      > +!5 = !{i32 1, !"wchar_size", i32 4}<br>
>      > +!6 = !{!"clang version 8.0.0 (trunk 343753)"}<br>
>      > +!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1,<br>
>     line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1,<br>
>     flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes:<br>
>     !11)<br>
>      > +!8 = !DISubroutineType(types: !9)<br>
>      > +!9 = !{!10}<br>
>      > +!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
>      > +!11 = !{!15}<br>
>      > +!13 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !10)<br>
>      > +!15 = !DILocalVariable(name: "brains", scope: !7, file: !1,<br>
>     line: 4, type: !10)<br>
>      > +!25 = !DILocation(line: 4, scope: !7)<br>
>      > +!26 = !DILocation(line: 6, scope: !27)<br>
>      > +!27 = distinct !DILexicalBlock(scope: !7, file: !1, line: 6)<br>
>      > +!28 = !DILocation(line: 6, scope: !7)<br>
>      > +!29 = !DILocation(line: 7, scope: !30)<br>
>      > +!30 = distinct !DILexicalBlock(scope: !27, file: !1, line: 6)<br>
>      > +!31 = !DILocation(line: 8, scope: !30)<br>
>      > +!32 = !DILocation(line: 9, scope: !30)<br>
>      > +!33 = !DILocation(line: 0, scope: !7)<br>
>      > +!34 = !DILocation(line: 12, scope: !7)<br>
>      > +!35 = !DILocation(line: 11, scope: !7)<br>
>      ><br>
>      > Modified: llvm/trunk/test/CodeGen/X86/pr38763.ll<br>
>      > URL:<br>
>     <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr38763.ll?rev=345250&r1=345249&r2=345250&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr38763.ll?rev=345250&r1=345249&r2=345250&view=diff</a><br>
>      ><br>
>     ==============================================================================<br>
>      > --- llvm/trunk/test/CodeGen/X86/pr38763.ll (original)<br>
>      > +++ llvm/trunk/test/CodeGen/X86/pr38763.ll Thu Oct 25 02:58:59 2018<br>
>      > @@ -30,13 +30,13 @@<br>
>      >   ; branches, as they becomes ambiguous.<br>
>      ><br>
>      >   ; CHECK-LABEL: entry<br>
>      > -; CHECK:  %cmp = icmp eq i32 %foo.0., 4<br>
>      > -; CHECK:  %add = add nsw i32 %foo.0.4, 2, !dbg !18<br>
>      > +; CHECK:  %cmp = icmp eq i32 %foo.0., 4, !dbg !14<br>
>      > +; CHECK:  %add = add nsw i32 %foo.0.4, 2, !dbg !16<br>
>      >   ; CHECK-NOT: @llvm.dbg.value(metadata i32 %add<br>
>      > -; CHECK:  %sub = add nsw i32 %foo.0.4, -2, !dbg !21<br>
>      > +; CHECK:  %sub = add nsw i32 %foo.0.4, -2, !dbg !16<br>
>      >   ; CHECK-NOT: @llvm.dbg.value(metadata i32 %sub<br>
>      >   ; CHECK:  %result.0 = select i1 %cmp, i32 %add, i32 %sub<br>
>      > -; CHECK:  call void @llvm.dbg.value(metadata i32 %result.0,<br>
>     metadata !12, metadata !DIExpression()), !dbg !17<br>
>      > +; CHECK:  call void @llvm.dbg.value(metadata i32 %result.0,<br>
>     metadata !12, metadata !DIExpression()), !dbg !13<br>
>      ><br>
>      >   ; ModuleID = 'pr38763.cpp'<br>
>      >   source_filename = "pr38763.cpp"<br>
>      > @@ -48,12 +48,12 @@ define dso_local i32 @main() local_unnam<br>
>      >   entry:<br>
>      >     %foo = alloca i32, align 4<br>
>      >     %foo.0..sroa_cast = bitcast i32* %foo to i8*<br>
>      > -  store volatile i32 4, i32* %foo, align 4, !tbaa !19<br>
>      > +  store volatile i32 4, i32* %foo, align 4<br>
>      >     %foo.0. = load volatile i32, i32* %foo, align 4<br>
>      >     %foo.0.4 = load volatile i32, i32* %foo, align 4<br>
>      >     call void @llvm.dbg.value(metadata i32 0, metadata !16,<br>
>     metadata !DIExpression()), !dbg !27<br>
>      > -  %cmp = icmp eq i32 %foo.0., 4<br>
>      > -  br i1 %cmp, label %if.then, label %if.else<br>
>      > +  %cmp = icmp eq i32 %foo.0., 4, !dbg !28<br>
>      > +  br i1 %cmp, label %if.then, label %if.else, !dbg !30<br>
>      ><br>
>      >   if.then:                                          ; preds = %entry<br>
>      >     %add = add nsw i32 %foo.0.4, 2, !dbg !31<br>
>      > @@ -91,12 +91,10 @@ declare void @llvm.dbg.value(metadata, m<br>
>      >   !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
>      >   !11 = !{!16}<br>
>      >   !16 = !DILocalVariable(name: "result", scope: !7, file: !1,<br>
>     line: 6, type: !10)<br>
>      > -!19 = !{!20, !20, i64 0}<br>
>      > -!20 = !{!"int", !21, i64 0}<br>
>      > -!21 = !{!"omnipotent char", !22, i64 0}<br>
>      > -!22 = !{!"Simple C++ TBAA"}<br>
>      >   !27 = !DILocation(line: 6, column: 7, scope: !7)<br>
>      > +!28 = !DILocation(line: 7, column: 12, scope: !29)<br>
>      >   !29 = distinct !DILexicalBlock(scope: !7, file: !1, line: 7,<br>
>     column: 7)<br>
>      > +!30 = !DILocation(line: 7, column: 7, scope: !7)<br>
>      >   !31 = !DILocation(line: 8, column: 20, scope: !32)<br>
>      >   !32 = distinct !DILexicalBlock(scope: !29, file: !1, line: 7,<br>
>     column: 18)<br>
>      >   !34 = !DILocation(line: 10, column: 20, scope: !35)<br>
>      ><br>
>      > Added: llvm/trunk/test/CodeGen/X86/pr39243.ll<br>
>      > URL:<br>
>     <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr39243.ll?rev=345250&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr39243.ll?rev=345250&view=auto</a><br>
>      ><br>
>     ==============================================================================<br>
>      > --- llvm/trunk/test/CodeGen/X86/pr39243.ll (added)<br>
>      > +++ llvm/trunk/test/CodeGen/X86/pr39243.ll Thu Oct 25 02:58:59 2018<br>
>      > @@ -0,0 +1,132 @@<br>
>      > +; RUN: opt < %s -S -simplifycfg | FileCheck %s<br>
>      > +<br>
>      > +; Note: This patch fixes the regression introduced by pr38762.<br>
>      > +;<br>
>      > +; When SimplifyCFG changes the PHI node into a select<br>
>     instruction, the debug<br>
>      > +; information becomes ambiguous. It causes the debugger to<br>
>     display unreached<br>
>      > +; lines and invalid variable values.<br>
>      > +;<br>
>      > +; When the function 'hoistAllInstructionsInto' hoist a basic block:<br>
>      > +; - Remove their dbg.values.<br>
>      > +; - Set their debug locations to the values from the insertion<br>
>     point.<br>
>      > +;<br>
>      > +; But, if one of the instructions being hoisted is a debug<br>
>     intrinsic from an<br>
>      > +; inlined function, assigning it the debug location from the<br>
>     insertion point<br>
>      > +; will create a mismatch between the intrinsic's subprogram and<br>
>     the location's<br>
>      > +; subprogram, causing the assertion "Expected inlined-at fields<br>
>     to agree" in<br>
>      > +; SelectionDAG".<br>
>      > +<br>
>      > +; IR generated with:<br>
>      > +; clang -S -g -gno-column-info -O2 -emit-llvm pr39243.cpp -o<br>
>     pr39243.ll -mllvm -opt-bisect-limit=103<br>
>      > +<br>
>      > +; // pr39243.cpp<br>
>      > +; union onion {<br>
>      > +;   double dd;<br>
>      > +;   int ii[2];<br>
>      > +; };<br>
>      > +;<br>
>      > +; int alpha;<br>
>      > +; int bravo();<br>
>      > +;<br>
>      > +; int charlie() {<br>
>      > +;   int delta = 0;<br>
>      > +;   return bravo();<br>
>      > +; }<br>
>      > +;<br>
>      > +; int echo(onion foxtrot) {<br>
>      > +;   alpha = foxtrot.ii[0];<br>
>      > +;   if (alpha) {<br>
>      > +;     int golf = bravo();<br>
>      > +;     return -golf;<br>
>      > +;   }<br>
>      > +;   alpha = foxtrot.ii[1];<br>
>      > +;   return -charlie();<br>
>      > +; }<br>
>      > +<br>
>      > +; Change the debug locations associated with the PHI nodes being<br>
>     promoted, to<br>
>      > +; the debug locations from the insertion point in the dominant<br>
>     block.<br>
>      > +<br>
>      > +; CHECK-LABEL: entry<br>
>      > +; CHECK:  %foxtrot.sroa.0.0.extract.trunc = trunc i64<br>
>     %foxtrot.coerce to i32<br>
>      > +; CHECK:  %tobool = icmp eq i32 %foxtrot.sroa.0.0.extract.trunc, 0<br>
>      > +; CHECK:  %foxtrot.sroa.2.0.extract.shift = lshr i64<br>
>     %foxtrot.coerce, 32<br>
>      > +; CHECK-NOT:  call void @llvm.dbg.value(metadata i32<br>
>     %foxtrot.sroa.2.0.extract.trunc, metadata !30, metadata<br>
>     !DIExpression(DW_OP_LLVM_fragment, 32, 32)), !dbg !34<br>
>      > +; CHECK:  %foxtrot.sroa.2.0.extract.trunc = trunc i64<br>
>     %foxtrot.sroa.2.0.extract.shift to i32<br>
>      > +; CHECK:  store i32 %foxtrot.sroa.2.0.extract.trunc, i32*<br>
>     @alpha, align 4, !dbg !25<br>
>      > +; CHECK-NOT:  call void @llvm.dbg.value(metadata i32 0, metadata<br>
>     !15, metadata !DIExpression()), !dbg !43<br>
>      > +<br>
>      > +; ModuleID = 'pr39243.cpp'<br>
>      > +source_filename = "pr39243.cpp"<br>
>      > +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>
>      > +target triple = "x86_64-pc-linux-gnu"<br>
>      > +<br>
>      > +@alpha = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0<br>
>      > +<br>
>      > +define dso_local i32 @_Z7charliev() local_unnamed_addr #0 {<br>
>      > +entry:<br>
>      > +  %call = tail call i32 @_Z5bravov()<br>
>      > +  ret i32 %call<br>
>      > +}<br>
>      > +<br>
>      > +declare dso_local i32 @_Z5bravov() local_unnamed_addr #1<br>
>      > +<br>
>      > +define dso_local i32 @_Z4echo5onion(i64 %foxtrot.coerce)<br>
>     local_unnamed_addr #0 !dbg !18 {<br>
>      > +entry:<br>
>      > +  %foxtrot.sroa.0.0.extract.trunc = trunc i64 %foxtrot.coerce to i32<br>
>      > +  store i32 %foxtrot.sroa.0.0.extract.trunc, i32* @alpha, align 4<br>
>      > +  %tobool = icmp eq i32 %foxtrot.sroa.0.0.extract.trunc, 0<br>
>      > +  br i1 %tobool, label %if.end, label %return<br>
>      > +<br>
>      > +if.end:                                           ; preds = %entry<br>
>      > +  %foxtrot.sroa.2.0.extract.shift = lshr i64 %foxtrot.coerce, 32<br>
>      > +  %foxtrot.sroa.2.0.extract.trunc = trunc i64<br>
>     %foxtrot.sroa.2.0.extract.shift to i32<br>
>      > +  call void @llvm.dbg.value(metadata i32<br>
>     %foxtrot.sroa.2.0.extract.trunc, metadata !30, metadata<br>
>     !DIExpression(DW_OP_LLVM_fragment, 32, 32)), !dbg !34<br>
>      > +  store i32 %foxtrot.sroa.2.0.extract.trunc, i32* @alpha, align<br>
>     4, !dbg !42<br>
>      > +  call void @llvm.dbg.value(metadata i32 0, metadata !15,<br>
>     metadata !DIExpression()), !dbg !43<br>
>      > +  br label %return<br>
>      > +<br>
>      > +return:                                           ; preds =<br>
>     %entry, %if.end<br>
>      > +  %call.i = tail call i32 @_Z5bravov()<br>
>      > +  %retval.0 = sub nsw i32 0, %call.i<br>
>      > +  ret i32 %retval.0<br>
>      > +}<br>
>      > +<br>
>      > +declare void @llvm.dbg.value(metadata, metadata, metadata) #2<br>
>      > +<br>
>      > +!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> <<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">http://llvm.dbg.cu</a>> = !{!2}<br>
>      > +!llvm.module.flags = !{!7, !8, !9}<br>
>      > +!llvm.ident = !{!10}<br>
>      > +<br>
>      > +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())<br>
>      > +!1 = distinct !DIGlobalVariable(name: "alpha", scope: !2, file:<br>
>     !3, line: 6, type: !6, isLocal: false, isDefinition: true)<br>
>      > +!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus,<br>
>     file: !3, producer: "clang version 8.0.0 (trunk 344502)",<br>
>     isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug,<br>
>     enums: !4, globals: !5, nameTableKind: None)<br>
>      > +!3 = !DIFile(filename: "pr39243.cpp", directory: ".")<br>
>      > +!4 = !{}<br>
>      > +!5 = !{!0}<br>
>      > +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
>      > +!7 = !{i32 2, !"Dwarf Version", i32 4}<br>
>      > +!8 = !{i32 2, !"Debug Info Version", i32 3}<br>
>      > +!9 = !{i32 1, !"wchar_size", i32 4}<br>
>      > +!10 = !{!"clang version 8.0.0 (trunk 344502)"}<br>
>      > +!11 = distinct !DISubprogram(name: "charlie", linkageName:<br>
>     "_Z7charliev", scope: !3, file: !3, line: 9, type: !12, isLocal:<br>
>     false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped,<br>
>     isOptimized: true, unit: !2, retainedNodes: !14)<br>
>      > +!12 = !DISubroutineType(types: !13)<br>
>      > +!13 = !{!6}<br>
>      > +!14 = !{!15}<br>
>      > +!15 = !DILocalVariable(name: "delta", scope: !11, file: !3,<br>
>     line: 10, type: !6)<br>
>      > +!18 = distinct !DISubprogram(name: "echo", linkageName:<br>
>     "_Z4echo5onion", scope: !3, file: !3, line: 14, type: !19, isLocal:<br>
>     false, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped,<br>
>     isOptimized: true, unit: !2, retainedNodes: !29)<br>
>      > +!19 = !DISubroutineType(types: !20)<br>
>      > +!20 = !{!6, !21}<br>
>      > +!21 = distinct !DICompositeType(tag: DW_TAG_union_type, name:<br>
>     "onion", file: !3, line: 1, size: 64, flags: DIFlagTypePassByValue |<br>
>     DIFlagTrivial, elements: !22, identifier: "_ZTS5onion")<br>
>      > +!22 = !{!23, !25}<br>
>      > +!23 = !DIDerivedType(tag: DW_TAG_member, name: "dd", scope: !21,<br>
>     file: !3, line: 2, baseType: !24, size: 64)<br>
>      > +!24 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)<br>
>      > +!25 = !DIDerivedType(tag: DW_TAG_member, name: "ii", scope: !21,<br>
>     file: !3, line: 3, baseType: !26, size: 64)<br>
>      > +!26 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6,<br>
>     size: 64, elements: !27)<br>
>      > +!27 = !{!28}<br>
>      > +!28 = !DISubrange(count: 2)<br>
>      > +!29 = !{!30}<br>
>      > +!30 = !DILocalVariable(name: "foxtrot", arg: 1, scope: !18,<br>
>     file: !3, line: 14, type: !21)<br>
>      > +!34 = !DILocation(line: 14, scope: !18)<br>
>      > +!42 = !DILocation(line: 20, scope: !18)<br>
>      > +!43 = !DILocation(line: 10, scope: !11, inlinedAt: !44)<br>
>      > +!44 = distinct !DILocation(line: 21, scope: !18)<br>
>      ><br>
>      ><br>
>      > _______________________________________________<br>
>      > llvm-commits mailing list<br>
>      > <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a> <mailto:<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>><br>
>      > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
>      ><br>
> <br>
<br>
</blockquote></div></div>