[llvm] r284415 - Ignore debug info when making optimization decisions in SimplifyCFG.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 12:28:45 PDT 2016
Author: dehao
Date: Mon Oct 17 14:28:44 2016
New Revision: 284415
URL: http://llvm.org/viewvc/llvm-project?rev=284415&view=rev
Log:
Ignore debug info when making optimization decisions in SimplifyCFG.
Summary: Debug info should *not* affect code generation. This patch properly handles debug info to make sure the generated code are the same with or without debug info.
Reviewers: davidxl, mzolotukhin, jmolloy
Subscribers: aprantl, llvm-commits
Differential Revision: https://reviews.llvm.org/D25286
Modified:
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=284415&r1=284414&r2=284415&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Mon Oct 17 14:28:44 2016
@@ -1485,8 +1485,14 @@ static bool sinkLastInstruction(ArrayRef
// canSinkLastInstruction returning true guarantees that every block has at
// least one non-terminator instruction.
SmallVector<Instruction*,4> Insts;
- for (auto *BB : Blocks)
- Insts.push_back(BB->getTerminator()->getPrevNode());
+ for (auto *BB : Blocks) {
+ Instruction *I = BB->getTerminator();
+ do {
+ I = I->getPrevNode();
+ } while (isa<DbgInfoIntrinsic>(I) && I != &BB->front());
+ if (!isa<DbgInfoIntrinsic>(I))
+ Insts.push_back(I);
+ }
// The only checking we need to do now is that all users of all instructions
// are the same PHI node. canSinkLastInstruction should have checked this but
@@ -1584,15 +1590,15 @@ namespace {
Fail = false;
Insts.clear();
for (auto *BB : Blocks) {
- if (Instruction *Terminator = BB->getTerminator()) {
- if (Instruction *LastNonTerminator = Terminator->getPrevNode()) {
- Insts.push_back(LastNonTerminator);
- continue;
- }
+ Instruction *Inst = BB->getTerminator();
+ for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
+ Inst = Inst->getPrevNode();
+ if (!Inst) {
+ // Block wasn't big enough.
+ Fail = true;
+ return;
}
- // Block wasn't big enough.
- Fail = true;
- return;
+ Insts.push_back(Inst);
}
}
@@ -1604,7 +1610,8 @@ namespace {
if (Fail)
return;
for (auto *&Inst : Insts) {
- Inst = Inst->getPrevNode();
+ for (Inst = Inst->getPrevNode(); Inst && isa<DbgInfoIntrinsic>(Inst);)
+ Inst = Inst->getPrevNode();
// Already at beginning of block.
if (!Inst) {
Fail = true;
Modified: llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll?rev=284415&r1=284414&r2=284415&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/sink-common-code.ll Mon Oct 17 14:28:44 2016
@@ -340,7 +340,7 @@ if.end:
; CHECK-LABEL: test13
; CHECK-DAG: select
; CHECK-DAG: load volatile
-; CHECK: store volatile {{.*}}, !tbaa !0
+; CHECK: store volatile {{.*}}, !tbaa ![[TBAA:[0-9]]]
; CHECK-NOT: load
; CHECK-NOT: store
@@ -384,6 +384,7 @@ if.else:
%gepb = getelementptr inbounds %struct.anon, %struct.anon* %s, i32 0, i32 1
%sv2 = load i32, i32* %gepb
%cmp2 = icmp eq i32 %sv2, 57
+ call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !9, metadata !DIExpression()), !dbg !11
br label %if.end
if.end:
@@ -391,6 +392,18 @@ if.end:
ret i32 1
}
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
+!llvm.module.flags = !{!5, !6}
+!llvm.dbg.cu = !{!7}
+
+!5 = !{i32 2, !"Dwarf Version", i32 4}
+!6 = !{i32 2, !"Debug Info Version", i32 3}
+!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !10)
+!8 = distinct !DISubprogram(name: "foo", unit: !7)
+!9 = !DILocalVariable(name: "b", line: 1, arg: 2, scope: !8)
+!10 = !DIFile(filename: "a.c", directory: "a/b")
+!11 = !DILocation(line: 1, column: 14, scope: !8)
+
; CHECK-LABEL: test14
; CHECK: getelementptr
; CHECK: load
@@ -781,6 +794,6 @@ merge:
; CHECK: right:
; CHECK-NEXT: %val1 = call i32 @call_target() [ "deopt"(i32 20) ]
-; CHECK: !0 = !{!1, !1, i64 0}
-; CHECK: !1 = !{!"float", !2}
-; CHECK: !2 = !{!"an example type tree"}
+; CHECK: ![[TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
+; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
+; CHECK: ![[TEXT]] = !{!"an example type tree"}
More information about the llvm-commits
mailing list