Open Quuxplusone opened 4 years ago
Attached abc.ll
(22668 bytes, text/plain): the IR file that triggers the potential bug
This optimization seems to be related to optimizeMax function in the
LoopStrengthReduce.cpp file. Specifically, the replacement of %exitcond to
%scmp should be related to the following lines in the source code:
// Ok, everything looks ok to change the condition into an SLT or SGE and
// delete the max calculation.
ICmpInst *NewCond =
new ICmpInst(Cond, Pred, Cond->getOperand(0), NewRHS, "scmp");
// Delete the max calculation instructions.
Cond->replaceAllUsesWith(NewCond);
If the debug location is not intentionally dropped, then a potential patch may
be inserting "NewCond->setDebugLoc(Cond->getDebugLoc());" before the
replaceAllUsesWith function call.
Yup, this looks faulty, certainly in the reproducer.
Yuanbo wrote:
> If the debug location is not intentionally dropped, then a potential patch may
> be inserting "NewCond->setDebugLoc(Cond->getDebugLoc());" before the
> replaceAllUsesWith function call.
Using the principles in:
https://llvm.org/docs/HowToUpdateDebugInfo.html
There's a one-to-one relationship between the new and old instruction, and it's
placed in the same location, so the DebugLoc should be preserved in the
reproducer.
I think the general case is a bit cloudier though: the new compare instruction
is moved around by some logic in OptimizeLoopTermCond that I don't immediately
understand. That might cause it to cross a block boundary, in which case we
might need to merge / drop DebugLocs at that point.
Attached file_48067.txt
(2997 bytes, text/plain): the reduced IR simplified.ll
abc.ll
(22668 bytes, text/plain)file_48067.txt
(2997 bytes, text/plain)