[llvm-bugs] [Bug 36104] New: LoopUnrollPass is not updating parameters of DbgValueInst correctly
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jan 25 22:56:41 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=36104
Bug ID: 36104
Summary: LoopUnrollPass is not updating parameters of
DbgValueInst correctly
Product: libraries
Version: 5.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Loop Optimizer
Assignee: unassignedbugs at nondot.org
Reporter: agupta at tifr.res.in
CC: llvm-bugs at lists.llvm.org
Consider following input to LoopUnroll pass to be unrolled two times.
define i32 @main() #0 !dbg !7 {
call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !11, metadata !12),
!dbg !13
br label %1, !dbg !14
; <label>:1: ; preds = %1, %0
%.0 = phi i32 [ 0, %0 ], [ %3, %1 ]
call void @llvm.dbg.value(metadata i32 %.0, i64 0, metadata !11, metadata
!12), !dbg !13
%2 = icmp slt i32 %.0, 5, !dbg !15
%3 = add nsw i32 %.0, 1, !dbg !18
call void @llvm.dbg.value(metadata i32 %3, i64 0, metadata !11, metadata
!12), !dbg !13
br i1 %2, label %1, label %4, !dbg !20, !llvm.loop !21
; <label>:4: ; preds = %1
ret i32 0, !dbg !23
}
After rotating and unrolling (unrolling requires rotating), we obtain:
define i32 @main() #0 !dbg !7 {
call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !11, metadata !12),
!dbg !13
br label %1, !dbg !14
; <label>:1: ; preds = %6, %0
%.0 = phi i32 [ 0, %0 ], [ %8, %6 ]
call void @llvm.dbg.value(metadata i32 %.0, i64 0, metadata !11, metadata
!12), !dbg !13
%2 = add nuw nsw i32 %.0, 1, !dbg !15
call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !11, metadata
!12), !dbg !13
call void @llvm.dbg.value(metadata i32 %.0, i64 0, metadata !11, metadata
!12), !dbg !13
%3 = icmp ult i32 %2, 5, !dbg !19
%4 = add nuw nsw i32 %2, 1, !dbg !15
call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !11, metadata
!12), !dbg !13
br i1 %3, label %6, label %5, !dbg !20, !llvm.loop !21
; <label>:5: ; preds = %1
ret i32 0, !dbg !23
; <label>:6: ; preds = %1
call void @llvm.dbg.value(metadata i32 %.0, i64 0, metadata !11, metadata
!12), !dbg !13
%7 = add nuw nsw i32 %4, 1, !dbg !15
call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !11, metadata
!12), !dbg !13
call void @llvm.dbg.value(metadata i32 %.0, i64 0, metadata !11, metadata
!12), !dbg !13
%8 = add nuw nsw i32 %7, 1, !dbg !15
call void @llvm.dbg.value(metadata i32 %2, i64 0, metadata !11, metadata
!12), !dbg !13
br label %1
}
Look at the the copied body in block 6. Note that the dbg.value after %7 is not
updated and still reflects %2. IMHO, it is wrong cloning of the block.
I think the problem lies in the following function of LoopUnroll.cpp:67
static inline void remapInstruction(Instruction *I,
ValueToValueMapTy &VMap) {
for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) {
Value *Op = I->getOperand(op); <<<<<<<------------------------
ValueToValueMapTy::iterator It = VMap.find(Op);
if (It != VMap.end())
I->setOperand(op, It->second); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
if (PHINode *PN = dyn_cast<PHINode>(I)) {
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
ValueToValueMapTy::iterator It = VMap.find(PN->getIncomingBlock(i));
if (It != VMap.end())
PN->setIncomingBlock(i, cast<BasicBlock>(It->second));
}
}
}
This function fails to pick the the right argument of a DbgValueInst. 0th Op is
not a Value but a metadata that contains the value %2 and needs one more
redirection to update the reference to %2.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180126/fd16c4c2/attachment.html>
More information about the llvm-bugs
mailing list