[llvm-commits] [LLVM, loop-unswitch] Potential bug in RewriteLoopBodyWithConditionConstant
Duncan Sands
baldrick at free.fr
Tue Nov 22 03:15:03 PST 2011
Hi Stepan,
> It seems that the code inside the
> LoopUnswitch::RewriteLoopBodyWithConditionConstant contains potential bugs.
> UseList is changed inside the loops that are goes through its items:
>
> LoopUnswitch.cpp, string #905: for (Value::use_iterator UI = LIC->use_begin(), E
> = LIC->use_end(); UI != E; ++UI) {
>
> ...and then inside the loop body UseList is changed implicitly (
> LoopUnswitch.cpp, string #910):
> U->replaceUsesOfWith(LIC, Replacement);
>
> It seems that after editing UseList loop may produce unpreditable results. But
> we are lucky by now though :-)
>
> I propose to collect all to be changed and then do some changes?
> If so, please find the patch attached for review.
can you just do something like this instead? Also, do you have a testcase?
Replacement = ConstantInt::get(Type::getInt1Ty(Val->getContext()),
!cast<ConstantInt>(Val)->getZExtValue());
for (Value::use_iterator UI = LIC->use_begin(), E = LIC->use_end();
- UI != E; ++UI) {
- Instruction *U = dyn_cast<Instruction>(*UI);
+ UI != E; ) {
+ Instruction *U = dyn_cast<Instruction>(*UI++);
if (!U || !L->contains(U))
continue;
U->replaceUsesOfWith(LIC, Replacement);
Worklist.push_back(U);
}
Ciao, Duncan.
More information about the llvm-commits
mailing list