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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 26 02:08:47 PDT 2020


lebedev.ri created this revision.
lebedev.ri added reviewers: efriedma, mkazantsev, reames, nikic.
lebedev.ri added a project: LLVM.
Herald added subscribers: javed.absar, hiraditya.
lebedev.ri added a parent revision: D82632: [NFCI][SCEV] getPointerBase(): de-recursify.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82633

Files:
  llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82633.273623.patch
Type: text/x-patch
Size: 7240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200626/774c214f/attachment.bin>


More information about the llvm-commits mailing list