This patch enable LoopReroll to reroll loop with pointer induction
variable, such as:
while (buf !=end ) {
S += buf[0];
S += buf[1];
buf +=2;
};Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
| lib/Transforms/Scalar/LoopRerollPass.cpp | ||
|---|---|---|
| 474 | dyn_cast -> cast (you've already tested IV->getType()->isPointerTy()). | |
| 502 | Don't you need an: } else {
break;
}here. If the MulSCEV operands are a constant and some other expression, you don't always want to return the constant). Also, do you want to look through extensions and/or truncations here? | |
| 1389 | I realize it was like this before, but we should name this something more explanatory than H. | |
| 1391 | This is not really just 'One', how about we name it IncExpr, or IncrementExpr, etc.? | |
| test/Transforms/LoopReroll/ptrindvar.ll | ||
| 43 | We should also have a test case where the pointer operand is being decremented. | |
Hi,
Thanks for working on this. I have plenty of comments :)
Cheers,
James
| lib/Transforms/Scalar/LoopRerollPass.cpp | ||
|---|---|---|
| 464 | This only works for pointers, not for integer steps, so can this be renamed to make that clear? | |
| 478 | Why declare NewSCEV here, instead of inside the if? | |
| 499 | I think this debug statement might not be that useful - can it be removed when committed? | |
| 500 | Braces {} around the else. if/elses should either both have braces or both not. | |
| 501 | Surely these breaks should be "return nullptr"? What if the first operand is a constant but the second is not an unknown? or is an unknown but !isSizeOf()? then currently you'll return the first operand but actually this method should fail. | |
| 515 | This would read better as: if (!I->getType()->isIntegerTy() && !I->getType()->isPointerTy()) | |
| 702 | It might read better if both these ifs were squashed together? | |
| 1389 | I really don't think "AddRecExpr" is any more helpful than "H". How about NewIVSCEV? | |
| 1390 | I don't like that these are declared outside of scope and initialized to nullptr - this isn't C, we can declare variables where we use them! :) Please sink these into the if expression (you can just use auto too) | |
| 1393 | You need to use cast<> instead of dyn_cast<> below. Instead, what you can do is this: if (auto *PTy = dyn_cast<PointerTy>(Inst->getType())) {then just use PTy below. | |
| 1400 | I realise it was like this before, but I don't actually think we need this to be of type SCEVAddRecExpr. I think const SCEV * should be sufficient, which means you can remove this cast. | |
| 1402 | I notice you've removed the compound braces around this but kept the comment... either keep the braces or remove the comment too, but give a rationale for removal if you're going to do that. | |
| 1415 | This nullptr initialization again... can we get rid of these? I mean, there seems to be no reason to even touch this line :/ | |
| 1423 | This is disingenuous, as Minus1SCEV no longer holds minus one! The variable should be renamed. | |
| 1430 | Please replace the braces you've removed here. Mixing one-liners and braces isn't LLVM style. | |
Thanks, James, most of your concerns are addressed
| lib/Transforms/Scalar/LoopRerollPass.cpp | ||
|---|---|---|
| 1390 | SizeOfExpr is used later, can't be declared in side if statement | |
Hi Lawrence,
I've got some more style complaints, but nothing major.
Cheers,
James
| lib/Transforms/Scalar/LoopRerollPass.cpp | ||
|---|---|---|
| 371 | Please either document this or move it to the protected: section below where all the helpers are. | |
| 466 | I don't think it's very useful to have this CIncSCEV variable. It'd be a lot neater (and more up to coding style) if instead of "CIncSCEV = ..; ...; return CIncSCEV;", just "return CIncSCEV;" | |
| 480 | return dyn_cast<SCEVConstant>(...); | |
| 481 | There should either be braces around both the if and else or around neither of them. | |
| 482 | return dyn_cast<SCEVConstant>(...) | |
| 493 | Braces or no braces, not mixed braces. | |
| 1420 | Please assert(SizeOfExpr); here, to ensure it's initialized (if someone changes the if() above!) | |
LGTM.
We should really get this enabled by default for functions when optimizing for size. Care to take a stab at that?
| lib/Transforms/Scalar/LoopRerollPass.cpp | ||
|---|---|---|
| 1375 | No space after first " | |
Sorry, I didn't realise that according to phab I was blocking this. I saw Hal's LGTM and ignored it.
Hi, Guys:
Very sorry that it took too long before I get back to this patch due to our release related work, now I need to rebase the code and fix the checking pattern of the testcase, could you please take a look again and give me a LGTM again? This time it will merged quickly.
Nice day.
Regards
Lawrence Hu
Please either document this or move it to the protected: section below where all the helpers are.