[llvm] r289704 - [InstCombine] Folding of a compare with RHS const should merge debug locations

Robert Lougher via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 14 12:27:22 PST 2016


Author: rlougher
Date: Wed Dec 14 14:27:22 2016
New Revision: 289704

URL: http://llvm.org/viewvc/llvm-project?rev=289704&view=rev
Log:
[InstCombine] Folding of a compare with RHS const should merge debug locations

If all the operands to a phi node are compares that have a RHS constant,
instcombine will try to pull them through the phi node, combining them into
a single operation. When it does this, the debug location of the new op
should be the merged debug locations of the phi node arguments.

Patch 8 of 8 for D26256.  Folding of a compare that has a RHS constant.

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

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
    llvm/trunk/test/DebugInfo/Generic/instcombine-phi.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp?rev=289704&r1=289703&r2=289704&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp Wed Dec 14 14:27:22 2016
@@ -583,7 +583,7 @@ Instruction *InstCombiner::FoldPHIArgOpI
   CmpInst *CIOp = cast<CmpInst>(FirstInst);
   CmpInst *NewCI = CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(),
                                    PhiVal, ConstantOp);
-  NewCI->setDebugLoc(FirstInst->getDebugLoc());
+  NewCI->setDebugLoc(PHIArgMergedDebugLoc(PN));
   return NewCI;
 }
 

Modified: llvm/trunk/test/DebugInfo/Generic/instcombine-phi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/instcombine-phi.ll?rev=289704&r1=289703&r2=289704&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/instcombine-phi.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/instcombine-phi.ll Wed Dec 14 14:27:22 2016
@@ -255,6 +255,49 @@ if.end:
   ret i32 %r.0, !dbg !52
 }
 
+; Test folding of a compare with RHS constant.  Generated from source (with
+; editing to common the zext):
+
+; extern int foo(void);
+; extern int bar(void);
+; 
+; int cmp_const(int a) {
+;   int r;
+;   if(a)
+;     r = foo() < 10;
+;   else
+;     r = bar() < 10;
+;   return r;
+; }
+
+; CHECK: define i32 @cmp_const
+; CHECK-LABEL: if.end:
+; CHECK: %[[PHI:.*]] = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
+; CHECK: icmp slt i32 %[[PHI]], 10
+; CHECK-NOT: !dbg
+; CHECK: ret i32
+
+define i32 @cmp_const(i32 %a) !dbg !53 {
+entry:
+  %tobool = icmp ne i32 %a, 0, !dbg !54
+  br i1 %tobool, label %if.then, label %if.else, !dbg !54
+
+if.then:                                          ; preds = %entry
+  %call = call i32 @foo(), !dbg !55
+  %cmp = icmp slt i32 %call, 10, !dbg !56
+  br label %if.end, !dbg !57
+
+if.else:                                          ; preds = %entry
+  %call1 = call i32 @bar(), !dbg !58
+  %cmp2 = icmp slt i32 %call1, 10, !dbg !59
+  br label %if.end
+
+if.end:                                           ; preds = %if.else, %if.then
+  %r.0 = phi i1 [ %cmp, %if.then ], [ %cmp2, %if.else ]
+  %conv = zext i1 %r.0 to i32
+  ret i32 %conv, !dbg !60
+}
+
 declare i32 @foo()
 declare i32 @bar()
 declare i64 @foo2()
@@ -317,3 +360,11 @@ declare i32* @bar3()
 !50 = !DILocation(line: 57, column: 9, scope: !45)
 !51 = !DILocation(line: 57, column: 15, scope: !45)
 !52 = !DILocation(line: 58, column: 3, scope: !45)
+!53 = distinct !DISubprogram(name: "cmp_const", scope: !1, file: !1, line: 61, type: !7, isLocal: false, isDefinition: true, scopeLine: 61, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!54 = !DILocation(line: 63, column: 6, scope: !53)
+!55 = !DILocation(line: 64, column: 9, scope: !53)
+!56 = !DILocation(line: 64, column: 15, scope: !53)
+!57 = !DILocation(line: 64, column: 5, scope: !53)
+!58 = !DILocation(line: 66, column: 9, scope: !53)
+!59 = !DILocation(line: 66, column: 15, scope: !53)
+!60 = !DILocation(line: 67, column: 3, scope: !53)




More information about the llvm-commits mailing list