Follow-up of D38677. This patch supports the vector type of both current and previous index when factoring out the current one into the previous one.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/IR/ConstantFold.cpp | ||
---|---|---|
2214 ↗ | (On Diff #121319) | You should be able to just use !isa<Constant>(Idxs[0]) for these kinds of checks I think. All GEP indices are required to be integers or integer vectors. |
2250 ↗ | (On Diff #121319) | This should be an else instead of an else if. Idxs[i] should be a vector here, so just cast it without checking. |
2253 ↗ | (On Diff #121319) | Use auto. |
2279–2280 ↗ | (On Diff #121319) | Use auto |
2285–2290 ↗ | (On Diff #121319) | This is confusing; I would get rid of it. The zero value is never used either. I would just use PrevIdx->getType->getNumVectorElements() or the equivalent for CurrIdx whenever you need IdxNumElements (see below for an example). |
2293 ↗ | (On Diff #121319) | CurrIdx = ConstantDataVector::getSplat(PrevIdx->getType()->getNumVectorElements(), CurrIdx); |
2296 ↗ | (On Diff #121319) | PrevIdx = ConstantDataVector::getSplat(CurrIdx->getType()->getNumVectorElements(), PrevIdx); |
lib/IR/ConstantFold.cpp | ||
---|---|---|
2214 ↗ | (On Diff #121319) | I think Unknown is set to true if we don't know the indices are inbound or not. Since we only check the bound for ConstantInt and ConstantDataVector, I just white list these two. It is true that the constant index can only be constant integer and constant integer vector, but wild constant expression (e.g. ptrtoint) is also allowed. If I change the code to !isa<Constant>, many test cases fail. |
One minor comment. Otherwise, this looks fine to me.
lib/IR/ConstantFold.cpp | ||
---|---|---|
2251 ↗ | (On Diff #123525) | Shouldn't this be an else with an unchecked cast? else { auto *CV = cast<ConstantDataVector>(Idxs[i]); ... } |