[all-commits] [llvm/llvm-project] f9f52c: [NFCI][SCEV] getPointerBase(): de-recursify

Roman Lebedev via All-commits all-commits at lists.llvm.org
Sat Jun 27 01:37:56 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: f9f52c88cafb11952a20eaa6d3b6cb2fcc79bbf9
      https://github.com/llvm/llvm-project/commit/f9f52c88cafb11952a20eaa6d3b6cb2fcc79bbf9
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-06-27 (Sat, 27 Jun 2020)

  Changed paths:
    M llvm/lib/Analysis/ScalarEvolution.cpp

  Log Message:
  -----------
  [NFCI][SCEV] getPointerBase(): de-recursify

Summary:
This is boringly straight-forward, each iteration we see if
V is some expression that we can look into, and if it has
a single pointer operand, then set V to that operand
and repeat.

Reviewers: efriedma, mkazantsev, reames, nikic

Reviewed By: nikic

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82632


  Commit: 141e845da5dda6743a09f858b4aec0133a931453
      https://github.com/llvm/llvm-project/commit/141e845da5dda6743a09f858b4aec0133a931453
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2020-06-27 (Sat, 27 Jun 2020)

  Changed paths:
    M llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
    M llvm/lib/Analysis/ScalarEvolution.cpp
    A llvm/test/Analysis/ScalarEvolution/add-expr-pointer-operand-sorting.ll

  Log Message:
  -----------
  [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


Compare: https://github.com/llvm/llvm-project/compare/f4aaed3bf16b...141e845da5dd


More information about the All-commits mailing list