[PATCH] D103660: [ScalarEvolution] Don't form min/max for pointer-type phi/select.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 15 23:11:46 PDT 2021


efriedma added a comment.

Here's a possible algorithm for determining pointer-ness of a SCEV expression:

1. SCEVUnknown is a pointer if and only if the LLVM IR value is a pointer.
2. SCEVPtrToInt is never a pointer.
3. If any other SCEV expression has no pointer operands, the result is an integer.
4. If a SCEVAddExpr has exactly one pointer operand, the result is a pointer.
5. If a SCEVAddRecExpr's first operand is a pointer, and it has no other pointer operands, the result is a pointer.
6. Otherwise, the SCEV expression is invalid.

Most of the results that come out of this algorithm aren't really controversial.  It doesn't make sense to multiply by a pointer, or divide by a pointer, or add two pointers to each other.

We could possibly add a rule like "If a SCEVMinMaxExpr has all pointer operands, the result is a pointer".  When I was looking at this originally, I was under the impression this would be problematic due to existing SCEV transforms, but looking again, maybe it's okay; I somehow thought the SCEV getter operations were more aggressive than they actually are.  If it does work out, that would allow me to narrow the scope of this patch to some extent.

In any case, the issue with createNodeForSelectOrPHI is that it likes to create expressions like, for example, `((-1 * %p) + ((1 + %p) umax (2 + %p)))`, where %p is a pointer.  (https://bugs.llvm.org/show_bug.cgi?id=46786#c17) This breaks any reasonable version of the above rules.

I'll mess with this a bit more.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103660/new/

https://reviews.llvm.org/D103660



More information about the llvm-commits mailing list