[llvm] [SCEV] Handle more adds in computeConstantDifference() (PR #101339)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 03:58:46 PDT 2024


nikic wrote:

> LGTM. Nice!
> 
> A couple of thoughts for follow on changes:
> 
>     1. I think you can handle mul -1, X by inverting multiplicity.  Could possibly handle other mul-by-constants too.

Yeah, support for multiplies is something I plan to add as a followup.
 
>     2. Once you did that, could we generalize this slightly to fold getMinusSCEV construction before resorting to the full add case?  That wouldn't be all zero multiplicities, but would return the operands and their multiplicity.

I think this is generally a good idea, but the details here are probably a bit tricky. One concern is flag preservation, and the other is that flattening SCEVs earlier can ultimately result in different expressions because our canonicalizations are inconsistent. Or at least I think I ran into this issue when trying something like that in the past.

> Actually, it looks like we have something like this in CollectAddOperandsWithScales, common/share?

This does conceptually the same thing, but the constraints are bit different. In particular, that one does want to create new SCEV nodes in some cases, which we don't want inside computeConstantDifference().

https://github.com/llvm/llvm-project/pull/101339


More information about the llvm-commits mailing list