This is an archive of the discontinued LLVM Phabricator instance.

[LAA] Analyze pointers forked by a phi
ClosedPublic

Authored by Allen on Aug 27 2023, 11:32 PM.

Details

Summary

Given a function like the following: https://godbolt.org/z/T9c99fr88

1161_noReadWrite(int *Preds) {
  for (int i = 0; i < LEN_1D-1; ++i) {
    if (Preds[i] != 0)
      b[i] = c[i] + 1;
    else
      a[i] = i * i;
  }
}

LLVM will optimize the IR to a single store by a phi instruction:

  %1 = load ptr, ptr @a, align 64
  %2 = load ptr, ptr @b, align 64
  ...
for.inc:
  %.sink = phi ptr [ %1, %if.then ], [ %2, %if.else ]
  %add.sink = phi double [ %add, %if.then ], [ %conv8, %if.else ]
  %arrayidx7 = getelementptr inbounds double, ptr %.sink, i64 %indvars.iv
  store double %add.sink, ptr %arrayidx7, align 8

LAA is currently unable to analyze such IR, since ScalarEvolution
will return a SCEVUnknown for the forked pointer operand of the store.

This patch adds initial optional support for analyzing both possibilities for the pointer
and allowing LAA to generate runtime checks for the bounds if required, refers to D108699, but here address the phi node.

Fixes https://github.com/llvm/llvm-project/issues/64888

Diff Detail

Event Timeline

Allen created this revision.Aug 27 2023, 11:32 PM
Allen requested review of this revision.Aug 27 2023, 11:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2023, 11:32 PM
Allen added a reviewer: nikic.Aug 28 2023, 3:42 AM
fhahn added a comment.Sep 1 2023, 5:03 AM

ping ?

Please keep the common courtesy ping rate of one week in mind (https://llvm.org/docs/Contributing.html#how-to-submit-a-patch)

llvm/lib/Analysis/LoopAccessAnalysis.cpp
930

Test case for this case?

Allen updated this revision to Diff 555377.Sep 1 2023, 7:52 AM

add a new test forked_ptrs_with_different_base3 according the comment

Allen marked an inline comment as done.Sep 1 2023, 8:59 AM
Allen added inline comments.
llvm/lib/Analysis/LoopAccessAnalysis.cpp
930

hi @fhahn, thanks for your comment.

I add a new test **forked_ptrs_with_different_base3 ** which have 3 operators of the PhiNode.
This revision was not accepted when it landed; it landed in state Needs Review.Sep 18 2023, 6:16 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.