This patch is to add the support of the value tracking of the alignment assume bundle.
Details
Diff Detail
Event Timeline
What does the third operand of an align bundle mean? It doesn't seem to be documented in LangRef.
llvm/lib/Analysis/ValueTracking.cpp | ||
---|---|---|
737 | You don't want to look for the bundle yourself. Use SmallVector<Attribute::AttrKind, 2> AttrKinds{Attribute::Align}; if (RetainedKnowledge RK = getKnowledgeValidInContext(V, AttrKinds, CtxI, DT, AC)) { ... } instead to account for all the interesting cases, e.g., multiple align bundles. Also, use braces for non trivial conditionals. I don't think the return is what you want here, other deductions might still apply. Also, I think we have alignment bundle -> Align information in the AlignmentFromAssumptions.cpp pass. We should create a helper function so this is less magic. |
You are right. My understanding is that align bundle of (p, 32, 24) assumes (p+24) is 32-byte aligned. - typo corrected.
That's correct. It matches the old llvm.assume alignment encoding via instructions.
I mentioned before that we should probably just create a gep with the offset instead of keeping it as a third operand but as long as we do we should have a helper to extract it from the bundle.
Rewrite the code using getKnowledgeValidInContext. The code is much cleaner than the previous version, but the result computed is less accurate if the size of the alignment bundle is three. I'll leave the improvement for the future, together with the improvement of value tracking of GEP (an example is that, with the future improvement, we can fold away the branch "br i1 %3, ...") in f2 of the added case assume-align.ll).
llvm/lib/Analysis/ValueTracking.cpp | ||
---|---|---|
737 |
Thanks for the comments and suggestions. I have rewrite the code using getKnowledgeValidInContext. Please take a look. Thanks |
Some nits you should address, otherwise LGTM.
FWIW, we should either not encode the offset but use a GEP, or make getKnowledgeValidInContext aware. Either should be a follow up.
llvm/lib/Analysis/ValueTracking.cpp | ||
---|---|---|
681 | I don't think the parenthesis part in the comment should be here. | |
llvm/test/Transforms/InstCombine/assume-align.ll | ||
48 | Instead of the comment above, add a TODO/FIXME here describing the two potential solutions to this problem. |
Reverse ping. More comments (nits) and notice that we should merge this, D89830 reimplemented it in the meantime, see my comment there too.
llvm/lib/Analysis/ValueTracking.cpp | ||
---|---|---|
676 | No need for the vector, replace it below with {Attribute::Alignment}. In D89830 @arichardson uses Log2_32 instead of countTrailingZeros. I think that makes sense since we have a power of 2. |
Updated to address review comments: I adopted the use of Log2_32 from D89830, removed the parenthesis comment, and added a TODO comment in the test case.
Thanks for the comments. I don’t have commit access. If we commit this first, I will need your help to commit for me (“Shimin Cui <scui@ca.ibm.com>”). Otherwise @arichardson can merge this with D89830 to commit both.
No need for the vector, replace it below with {Attribute::Alignment}.
In D89830 @arichardson uses Log2_32 instead of countTrailingZeros. I think that makes sense since we have a power of 2.