HomePhabricator

[SCEV] BuildConstantFromSCEV(): properly handle SCEVZeroExtend from ptr

Authored by lebedev.ri on Oct 13 2020, 1:45 AM.

Description

[SCEV] BuildConstantFromSCEV(): properly handle SCEVZeroExtend from ptr

As being reported in https://reviews.llvm.org/D88806#2326944,
this is pretty much the sibling problem of https://reviews.llvm.org/D88806#2325340,
with root cause being that SCEV now models ptrtoint as trunc/zext/self of unknown.

The appropriate (currently crashing) test coverage added.

Event Timeline

arichardson added inline comments.
/llvm/lib/Analysis/ScalarEvolution.cpp
7990

Isn't the same change also required here?

lebedev.ri marked an inline comment as done.Oct 13 2020, 2:08 AM
lebedev.ri added inline comments.
/llvm/lib/Analysis/ScalarEvolution.cpp
7990

After D88774, SCEVZeroExtendExpr and SCEVTruncateExpr can have a pointer operand and integer output
because D88774 (as you can see) models IR's ptrtoint as per it's langref description:
cast to a pointer-sized integer and either truncate or zero-extend to the destination integer bit width.
So right now i don't know that SCEVSignExtendExpr also needs to deal with pointer input.
Maybe it does, maybe it does not.

arichardson added inline comments.Oct 13 2020, 2:18 AM
/llvm/lib/Analysis/ScalarEvolution.cpp
7990

Thanks for the explanation, I'm not particularly familar with SCEV so wasn't sure whether there could be a case where such a pattern could be created. I just saw some comments like sext(trunc(x)) --> sext(x) so maybe some other expressions can end up being turned into a sext of a pointer.

lebedev.ri marked 2 inline comments as done.Oct 13 2020, 2:20 AM
lebedev.ri added inline comments.
/llvm/lib/Analysis/ScalarEvolution.cpp
7990

That being said, digged a bit, and fixed in rGaaafe350bb65dfc24c2cdad4839059ac81899fbe, thanks!