For a pointer phi, we can strenghten the underlying object if each of
its incoming pointers are the same, or the PHI itself.
Some benefits are:
- Stronger alias analysis
- Folding phis that point to a zero initialized constant array
Paths
| Differential D152082
[ValueTracking] getUnderlyingObject() look through phi. AbandonedPublic Authored by caojoshua on Jun 3 2023, 2:36 PM.
Details
Summary For a pointer phi, we can strenghten the underlying object if each of Some benefits are:
Diff Detail
Event TimelineComment Actions I think this analysis of objects is correct. Would appreciate if reviewers let me know whether my understanding is correct or not. This change is on top of a local NFC to make getUnderlyingObject() recursive. Some caveats:
Comment Actions If you upload the base revision I can check, but I'm pretty confident that this is not viable from a compile-time perspective. getUnderlyingObject() is very performance critical, and we rely on the fact that this operation is "essentially free". We have a separate getUnderlyingObjects() function that can recurse though selects and phis. This revision now requires changes to proceed.Jun 4 2023, 12:13 AM Comment Actions Capture Count variable by reference, and increment it once each time Visit() is called. This hopefully alleviates some compile-time concerns. When looking through PHIs, each operand will increment the same Count. Comment Actions
Please check if you are able to. I have uploaded to https://github.com/caojoshua/llvm-project/tree/underlyingphi. My hope is that with the default MaxLookup = 6, the compile time does not see significant impact. I just uploaded some new changes that hopefully makes compile time better. Comment Actions Comment Actions
The NFC patch itself creates a regression. I don't think the recursion is an issue, since I see on my local build the tail recursion is eliminated. I suspect removing the std::function might be sufficient to eliminate regression. For the main patch, it looks unrealistic to eliminate compile-time regression. I think this functionality could be useful for some callers, maybe it would be good to create a different code path that does not touch the existing getUnderlyingObject. Comment Actions I tried reducing the compile time in https://github.com/caojoshua/llvm-project/tree/underlyingperf. From local results, I'm able to eliminate regressions in the NFC by moving away from std::function. Regressions are still very significant for the functionality changing patch.
Revision Contents
Diff 528192 llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/BasicAA/phi-aa.ll
llvm/test/Analysis/BasicAA/recphi.ll
llvm/test/CodeGen/AArch64/aarch64-matrix-umull-smull.ll
llvm/test/CodeGen/AMDGPU/promote-alloca-to-lds-phi.ll
llvm/test/CodeGen/ARM/arm-shrink-wrapping-linux.ll
llvm/test/CodeGen/Thumb2/mve-memtp-loop.ll
llvm/test/Transforms/InstCombine/ptr-replace-alloca.ll
llvm/test/Transforms/LoopVectorize/ARM/pointer_iv.ll
llvm/test/Transforms/LoopVectorize/X86/gather_scatter.ll
|
How often is the cache hit?