This is an archive of the discontinued LLVM Phabricator instance.

[LAA] Support forked pointer in the form of phi
AbandonedPublic

Authored by Allen on Aug 22 2023, 1:07 AM.

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, depand on D108699

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

Diff Detail

Unit TestsFailed

Event Timeline

Allen created this revision.Aug 22 2023, 1:07 AM
Allen requested review of this revision.Aug 22 2023, 1:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2023, 1:07 AM
Allen updated this revision to Diff 552276.Aug 22 2023, 2:43 AM

Fix the failure test Analysis/LoopAccessAnalysis/nullptr.ll

dewen added a subscriber: dewen.Aug 22 2023, 6:58 PM
Allen added a comment.Aug 27 2023, 6:07 PM

I'm relatively new to making changes to LAA. Please don't hold back if this is the wrong approach, I'm happy to put legwork in to finding the right route to making this work, thanks.

Allen planned changes to this revision.Aug 27 2023, 11:37 PM

a new implementation solution on D158965, which doesn't depend on the rebase on D158334

Allen abandoned this revision.Sep 1 2023, 7:57 AM