summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorRobert Lougher <rob.lougher@gmail.com>2016-12-14 18:14:57 +0000
committerRobert Lougher <rob.lougher@gmail.com>2016-12-14 18:14:57 +0000
commit4b0790d488db749fa3ec545d7d833a7cea603035 (patch)
treecefd85e0cbf05d8b1c21cbf9d4ed55880ac730bc /llvm
parentd9d9a545119d6538a94e90989c5cf0147cb02a8a (diff)
downloadbcm5719-llvm-4b0790d488db749fa3ec545d7d833a7cea603035.tar.gz
bcm5719-llvm-4b0790d488db749fa3ec545d7d833a7cea603035.zip
[InstCombine] Merge debug locations when folding through a phi node
If all the operands to a phi node are of the same operation, 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 operation should be the merged debug locations of the phi node arguments. Patch 3 of 8 for D26256. Folding of a compare operation. Differential Revision: https://reviews.llvm.org/D26256 llvm-svn: 289681
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp2
-rw-r--r--llvm/test/DebugInfo/Generic/instcombine-phi.ll51
2 files changed, 52 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
index 91bfe6c5c82..c288886fafb 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
@@ -117,7 +117,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
if (CmpInst *CIOp = dyn_cast<CmpInst>(FirstInst)) {
CmpInst *NewCI = CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(),
LHSVal, RHSVal);
- NewCI->setDebugLoc(FirstInst->getDebugLoc());
+ NewCI->setDebugLoc(PHIArgMergedDebugLoc(PN));
return NewCI;
}
diff --git a/llvm/test/DebugInfo/Generic/instcombine-phi.ll b/llvm/test/DebugInfo/Generic/instcombine-phi.ll
index 8d8e1cd3c06..a9893aeb32f 100644
--- a/llvm/test/DebugInfo/Generic/instcombine-phi.ll
+++ b/llvm/test/DebugInfo/Generic/instcombine-phi.ll
@@ -48,6 +48,49 @@ if.end: ; preds = %if.else, %if.then
ret i32 %b.addr.0, !dbg !14
}
+; Test folding of a compare. Generated from source (with editing to
+; common the zext):
+
+; extern int foo(void);
+; extern int bar(void);
+;
+; int cmp(int a, int b) {
+; int r;
+; if(a)
+; r = foo() < b;
+; else
+; r = bar() < b;
+; return r;
+; }
+
+; CHECK: define i32 @cmp
+; CHECK-LABEL: if.end:
+; CHECK: %[[PHI:.*]] = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
+; CHECK: icmp slt i32 %[[PHI]], %b
+; CHECK-NOT: !dbg
+; CHECK: ret i32
+
+define i32 @cmp(i32 %a, i32 %b) !dbg !15 {
+entry:
+ %tobool = icmp ne i32 %a, 0, !dbg !16
+ br i1 %tobool, label %if.then, label %if.else, !dbg !16
+
+if.then: ; preds = %entry
+ %call = call i32 @foo(), !dbg !17
+ %cmp = icmp slt i32 %call, %b, !dbg !18
+ br label %if.end, !dbg !19
+
+if.else: ; preds = %entry
+ %call1 = call i32 @bar(), !dbg !20
+ %cmp2 = icmp slt i32 %call1, %b, !dbg !21
+ 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 !22
+}
+
declare i32 @foo()
declare i32 @bar()
@@ -68,3 +111,11 @@ declare i32 @bar()
!12 = !DILocation(line: 12, column: 10, scope: !6)
!13 = !DILocation(line: 12, column: 7, scope: !6)
!14 = !DILocation(line: 13, column: 3, scope: !6)
+!15 = distinct !DISubprogram(name: "cmp", scope: !1, file: !1, line: 16, type: !7, isLocal: false, isDefinition: true, scopeLine: 16, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!16 = !DILocation(line: 18, column: 6, scope: !15)
+!17 = !DILocation(line: 19, column: 9, scope: !15)
+!18 = !DILocation(line: 19, column: 15, scope: !15)
+!19 = !DILocation(line: 19, column: 5, scope: !15)
+!20 = !DILocation(line: 21, column: 9, scope: !15)
+!21 = !DILocation(line: 21, column: 15, scope: !15)
+!22 = !DILocation(line: 22, column: 3, scope: !15)
OpenPOWER on IntegriCloud