This is an archive of the discontinued LLVM Phabricator instance.

[Attributor] Deduce "align" attribute
ClosedPublic

Authored by uenoku on Jul 3 2019, 12:26 PM.

Diff Detail

Event Timeline

uenoku created this revision.Jul 3 2019, 12:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 3 2019, 12:26 PM
uenoku updated this revision to Diff 207864.Jul 3 2019, 12:37 PM

Fix patch

uenoku marked an inline comment as done.Jul 3 2019, 12:45 PM

@jdoerfert
I know align attribute is integer attribute and we need somewhat different deduction with other attributes. However, I implement AAAlignImpl as a subclass of BooleanState for now. Is it better to add some base class for the integer attribute?

llvm/test/Transforms/FunctionAttrs/align.ll
36

I want to test this for

if (ICS && ICS.hasRetAttr(Attribute::Alignment))
  return CompareOrSet(ICS.getRetAlignment());

but it does not work well now.
I find that ICS.hasRetAttr(Attribute::Alignment) returns true but ICS.getRetAlignment() returns 0 and get error in the current implementation. I think maybe that this is parse level problem... I'll investigate more.

@jdoerfert
I know align attribute is integer attribute and we need somewhat different deduction with other attributes. However, I implement AAAlignImpl as a subclass of BooleanState for now. Is it better to add some base class for the integer attribute?

Why not make it derive from IntegerState and use the integer as the alignment, zero would be the worst possible = unknown.

jdoerfert added inline comments.Jul 3 2019, 2:18 PM
llvm/include/llvm/Transforms/IPO/Attributor.h
696

Please add getters for the assumed and known alignment here.

llvm/lib/Transforms/IPO/Attributor.cpp
803

Can you unify the two initialize methods in the base class (AAAlignImpl) with the index trick used in addIfNotExistent?

827

What you want to do use to take the minimum of all align values and the current state (IntegerState). Remember the state at the beginning of this function to determine if it changed. We also need a test for this.

839

For the return value you should do two things (for now):

  1. Use Value::getPointerAlignment to get the known alignment in the IR.
  2. Use getAAFor<AAAlign>() to the the known and assumed alignment from the Attributor.

Later, 1) would be replaced by a new ValueTracking.h getPointerAlignment method that does traversal, e.g., look through casts, compute new alignment based on constant geps, etc.
Later later, the new 1) and 2) would be merged to use traversal and assumed alignment together.

You can work on the later points as well if you want.

859

There is (probably) no need for the ExistsAssume trick here, you can leave it but add a comment to explain that it is a shortcut to identify an optimistic fixpoint.

llvm/test/Transforms/FunctionAttrs/align.ll
23

We want align 4 here.

uenoku updated this revision to Diff 208063.Jul 4 2019, 11:34 AM

Use IntegerState and take a minimum of alignment.

uenoku marked 4 inline comments as done.Jul 4 2019, 11:35 AM
uenoku updated this revision to Diff 208102.Jul 4 2019, 5:50 PM
uenoku marked 2 inline comments as done and an inline comment as not done.

Use getPointerAlignment.

jdoerfert added inline comments.Jul 5 2019, 12:02 PM
llvm/lib/Transforms/IPO/Attributor.cpp
257

I think you want to return -1 so it is clearly not a valid argument position.

772

return value or argument, right?

776

One could use the existing attribute as "known" and not indicate a fixpoint so that we can compute a better value.
We should have a test for it even if you keep it this way to describe the possibility.

786

Why the if? Can't you take the minimum of the knownAlign and the maximum allowed? Or initialize the assumed to the maximum allowed value already in the initialization?

787

style: remove braces around single statements.

790

I think you want to first look at the in-flight AAAlign attribute before you look at the IR.

838

If there is no top state, we can reach optimistic fixpoint earlier.

"If no assumed state was used for reasoning, an optimistic fixpoint is reached earlier."

llvm/test/Transforms/FunctionAttrs/align.ll
43

Can we have SCC tests as well

uenoku updated this revision to Diff 208608.Jul 9 2019, 1:22 AM
uenoku marked 6 inline comments as done.

Address comments.

uenoku updated this revision to Diff 211444.EditedJul 24 2019, 1:49 AM
uenoku retitled this revision from [Attributor] Deduce "align" attribute on return value to [Attributor] Deduce "align" attribute .
uenoku edited the summary of this revision. (Show Details)

Rebase and add callsite argument and argument deduction. It is ready for review.

uenoku updated this revision to Diff 211567.Jul 24 2019, 11:12 AM

Minor update

jdoerfert added inline comments.Jul 24 2019, 12:43 PM
llvm/lib/Transforms/IPO/Attributor.cpp
866

Are the statistics missing?

870

Make the 1U << 29 a static const member with a proper name and description.

874

The state is not initialized here as above. Call the general constructor from the specialized one (above) to avoid such inconsistencies.

912

I think we should, for consistency, call getAssumedAlign() here.

1019

remove isPointerTy, see above.

llvm/test/Transforms/FunctionAttrs/align.ll
44

What happened to test5 again? Why is it commented out?

58

Please add a more meaningful SCC test, 3 functions, conditionals, malloc, etc. This one is a no-return recursion for which we can deduce everything.

76

check the call sites.

uenoku updated this revision to Diff 211732.Jul 25 2019, 5:55 AM

Address comments

uenoku marked 3 inline comments as done.Jul 25 2019, 7:04 AM
uenoku added inline comments.
llvm/test/Transforms/FunctionAttrs/align.ll
44

The problem was that getPointerAlignment didn't work well in test5_2. This will be fixed in D65281.

This revision is now accepted and ready to land.Jul 27 2019, 10:24 PM
uenoku updated this revision to Diff 212080.Jul 27 2019, 11:49 PM
uenoku marked an inline comment as done.

Minor fix.

This revision was automatically updated to reflect the committed changes.