[PATCH] D104498: [WIP][ScalarEvolution] Strictly enforce pointer/int type rules.

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 22 20:39:51 PDT 2021


reames added a comment.

(This comment is largely an aside, just recording a thought on a vaguely related topic.  This has nothing to do with non-integral pointers directly.)

As a further aside, the overlap check we generate in e.g. loop-versioning-licm* is:

  %scevgep = getelementptr i8, i8* %a, i64 4
  %scevgep1 = getelementptr i8, i8* %b, i64 4
  %bound0 = icmp ult i8* %a, %scevgep1
  %bound1 = icmp ult i8* %b, %scevgep
  %found.conflict = and i1 %bound0, %bound1

This does gets codegened as two distinct checks on x86.

If subtract of pointers was valid in IR, we could instead write:

  %diff = sub i8* %a, %b ;; pretend result type is i64
  %bound0 = icmp slt i64 %diff, 4
  %bound1 = icmp sgt i64 %diff, -4
  %found.conflict = and i1 %bound0, %bound1

Which reduces to:

  %diff = sub i8* %a, %b ;; pretend result type is i64
  %diff.off = add i64 %diff, 3
  %1 = icmp ult i64 %diff.off, 7

- This was the easiest example to exercise, from code structure the loop vectorizer does the same when versioning.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104498



More information about the llvm-commits mailing list