This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] Make SCEVAddExpr actually always return pointer type if there is pointer operand (PR46457)
ClosedPublic

Authored by lebedev.ri on Jun 26 2020, 2:06 AM.

Details

Summary

The added assertion fails on the added test without the fix.

Reduced from test-suite/MultiSource/Benchmarks/MiBench/office-ispell/correct.c
In IR, getelementptr, obviously, takes pointer as it's base,
and returns a pointer.

When creating an SCEV expression, SCEV operands are sorted in hope
that it increases folding potential, and at the same time SCEVAddExpr's
type is the type of the last(!) operand.

Which means, in some exceedingly rare cases, pointer operand may happen to
end up not being the last operand, and as a result SCEV for GEP
will suddenly have a non-pointer return type.
We should ensure that does not happen.

In the end, actually storing the Type *, at the cost of increasing
memory footprint of SCEVAddExpr, appears to be the solution.
We can't just store a 'is a pointer' bit and create pointer type
on the fly since we don't have data layout in getType().

Fixes PR46457

Diff Detail