OSDN Git Service

[SCEV] Make SCEVAddExpr actually always return pointer type if there is pointer opera...
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 27 Jun 2020 08:34:58 +0000 (11:34 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 27 Jun 2020 08:37:17 +0000 (11:37 +0300)
commit141e845da5dda6743a09f858b4aec0133a931453
tree195a5d5d5d2b67228be4b8b50eb911cda3cd65fa
parentf9f52c88cafb11952a20eaa6d3b6cb2fcc79bbf9
[SCEV] Make SCEVAddExpr actually always return pointer type if there is pointer operand (PR46457)

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 [[ https://bugs.llvm.org/show_bug.cgi?id=46457 | PR46457 ]]

Reviewers: efriedma, mkazantsev, reames, nikic

Reviewed By: efriedma

Subscribers: hiraditya, javed.absar, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82633
llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll [new file with mode: 0644]