This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Have `cloneArithmeticIVUser` guess better
ClosedPublic

Authored by sanjoy on Oct 13 2015, 7:49 PM.

Details

Summary

cloneArithmeticIVUser currently trips over expression like `add %iv,
-1` when %iv is being zero extended -- it tries to construct the
widened use as add %iv.zext, zext(-1) and (correctly) fails to prove
equivalence to zext(add %iv, -1) (here the SCEV for %iv is
{1,+,1}).

This change teaches IndVars to try sign extending the non-IV operand
if that makes the newly constructed IV use equivalent to the widened
narrow IV use.

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 37315.Oct 13 2015, 7:49 PM
sanjoy retitled this revision from to [IndVars] Have `cloneArithmeticIVUser` guess better.
sanjoy updated this object.
sanjoy added reviewers: atrick, hfinkel, reames.
sanjoy added a subscriber: llvm-commits.
reames added inline comments.Oct 14 2015, 12:11 PM
lib/Transforms/Scalar/IndVarSimplify.cpp
996

Pulling out these variables is an NFC change. Can you separate and commit? It'll make the diff easier.

1006

This would be more clear as a lambda which captures SE

Actually, doesn't SCEV have a GetExtend w/a signed param? I know IR builder does. Adding one wouldn't be unreasonable.

1025

Isn't there something along the lines of SE->getBinOp?

1042

Comment? Where'd WideAR come from?

1079

Why not use auto here?

sanjoy updated this revision to Diff 37381.Oct 14 2015, 1:05 PM
sanjoy marked 4 inline comments as done.
  • address review
sanjoy added inline comments.Oct 14 2015, 1:07 PM
lib/Transforms/Scalar/IndVarSimplify.cpp
1025

Coud not find any such thing.

1042

Added a comment explaining what's going on.

reames edited edge metadata.Oct 15 2015, 3:34 PM

I have only minor comments, but I'm not familiar enough with the surrounding code to spot any subtle mistakes. I'll say LGTM, but take that for what it's worth.

lib/Transforms/Scalar/IndVarSimplify.cpp
1061

I'd restructure this to put the assignment before the second guess. It would make it more obvious what's going on.

1068

The fact this function is also called getExtend is confusing. getExtend != GetExtend?

This revision was automatically updated to reflect the committed changes.
sanjoy marked an inline comment as done.