This is an archive of the discontinued LLVM Phabricator instance.

[BasicAA] Fix a bug with relational reasoning across iterations
ClosedPublic

Authored by reames on Dec 4 2020, 2:23 PM.

Details

Summary

Due to the recursion through phis basicaa does, the code needs to be extremely careful not to reason about equality between values which might represent distinct iterations. I'm generally skeptical of the correctness of the whole scheme, but this particular patch fixes one particular instance which is demonstrateable incorrect.

Interestingly, this appears to be the second attempted fix for the same issue. The former fix is incomplete and doesn't address the actual issue.

Diff Detail

Event Timeline

reames created this revision.Dec 4 2020, 2:23 PM
reames requested review of this revision.Dec 4 2020, 2:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2020, 2:23 PM
reames added inline comments.Dec 4 2020, 2:24 PM
llvm/test/Analysis/BasicAA/phi-aa.ll
179

Previously, we'd (falsely) conclude that %phi noalias %arrayidx5. Since the value of %idx can vary across iterations, this is wrong.

Looks sensible to me. Second opinion preferred though.

nikic accepted this revision.Dec 5 2020, 2:55 AM

LGTM

Due diligence: I was a bit concerned about dropping the known bits fallback (which we can retain even in cycles). After adding some AA stats, I see:

               | Baseline |    Patch
aa.NumMayAlias |  4920438 |  4920375
aa.NumNoAlias  | 27075701 | 27075764

So this actually marginally improves the AA results. Presumably that's because we can now handle the case where one of the indexes is a phi, but we're not in a cycle.

This revision is now accepted and ready to land.Dec 5 2020, 2:55 AM