From 17670a995c2cf40e94661b1d21c8bbe3ed742913 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 7 Apr 2011 17:27:36 +0000 Subject: [PATCH] While hoisting common code from if/else, hoist debug info intrinsics if they match. llvm-svn: 129078 --- lib/Transforms/Utils/SimplifyCFG.cpp | 26 ++++++--- test/Transforms/SimplifyCFG/hoist-dbgvalue.ll | 53 +++++++++++++++++++ 2 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 test/Transforms/SimplifyCFG/hoist-dbgvalue.ll diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index 286b1653494..27f77218f4c 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -807,10 +807,15 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) { BasicBlock::iterator BB2_Itr = BB2->begin(); Instruction *I1 = BB1_Itr++, *I2 = BB2_Itr++; - while (isa(I1)) - I1 = BB1_Itr++; - while (isa(I2)) - I2 = BB2_Itr++; + // Skip debug info if it is not identical. + DbgInfoIntrinsic *DBI1 = dyn_cast(I1); + DbgInfoIntrinsic *DBI2 = dyn_cast(I2); + if (!DBI1 || !DBI2 || !DBI1->isIdenticalToWhenDefined(DBI2)) { + while (isa(I1)) + I1 = BB1_Itr++; + while (isa(I2)) + I2 = BB2_Itr++; + } if (isa(I1) || !I1->isIdenticalToWhenDefined(I2) || (isa(I1) && !isSafeToHoistInvoke(BB1, BB2, I1, I2))) return false; @@ -834,11 +839,16 @@ static bool HoistThenElseCodeToIf(BranchInst *BI) { I2->eraseFromParent(); I1 = BB1_Itr++; - while (isa(I1)) - I1 = BB1_Itr++; I2 = BB2_Itr++; - while (isa(I2)) - I2 = BB2_Itr++; + // Skip debug info if it is not identical. + DbgInfoIntrinsic *DBI1 = dyn_cast(I1); + DbgInfoIntrinsic *DBI2 = dyn_cast(I2); + if (!DBI1 || !DBI2 || !DBI1->isIdenticalToWhenDefined(DBI2)) { + while (isa(I1)) + I1 = BB1_Itr++; + while (isa(I2)) + I2 = BB2_Itr++; + } } while (I1->isIdenticalToWhenDefined(I2)); return true; diff --git a/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll b/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll new file mode 100644 index 00000000000..03053f037d0 --- /dev/null +++ b/test/Transforms/SimplifyCFG/hoist-dbgvalue.ll @@ -0,0 +1,53 @@ +; RUN: opt -simplifycfg -S < %s | FileCheck %s + +define i32 @foo(i32 %i) nounwind ssp { + call void @llvm.dbg.value(metadata !{i32 %i}, i64 0, metadata !6), !dbg !7 + call void @llvm.dbg.value(metadata !8, i64 0, metadata !9), !dbg !11 + %1 = icmp ne i32 %i, 0, !dbg !12 +;CHECK: call i32 (...)* @bar() +;CHECK-NEXT: llvm.dbg.value + br i1 %1, label %2, label %4, !dbg !12 + +;