This is an archive of the discontinued LLVM Phabricator instance.

[AlignmentFromAssumptions] Fix a SCEV assertion resulting from address space differences.
ClosedPublic

Authored by DiamondLovesYou on Mar 2 2020, 10:15 AM.

Details

Summary

On targets with different pointer sizes, -alignment-from-assumptions could attempt to create SCEV expressions which use different effective SCEV types. The provided test illustrates the issue.

In getNewAlignment, AASCEV would be the (only) alloca, which would have an effective SCEV type of i32. But PtrSCEV, the GEP in this case, due to being in the flat/default address space, will have an effective SCEV of i64.

This patch resolves the issue by truncating PtrSCEV to AASCEV's effective type.

Diff Detail

Event Timeline

Fix CI issue ("no CHECK line").

I think this is generally fine, except the test case changes noted below.

FWIW, this pass will be deleted (hopefully soon).

llvm/test/Transforms/AlignmentFromAssumptions/amdgpu-crash.ll
4

If you want to test for "non-crash", remove the FileCheck. However, I think you want to test that the generated expression is actually as expected instead.

48

Please remove all these attributes and metadata notes, etc., none of it should be needed.

Is this still active?

jdoerfert requested changes to this revision.Mar 19 2020, 9:41 PM
This revision now requires changes to proceed.Mar 19 2020, 9:41 PM
DiamondLovesYou updated this revision to Diff 252114.EditedMar 23 2020, 12:04 PM

Clean up the test.

DiamondLovesYou marked 3 inline comments as done.Mar 23 2020, 12:20 PM

Sorry for the delay; yes this is still active.

llvm/test/Transforms/AlignmentFromAssumptions/amdgpu-crash.ll
4

If you want to test for "non-crash", remove the FileCheck.

Ah, should have known, thanks.

I think you want to test that the generated expression is actually as expected instead.

There's nothing to test (aside from not crashing): -alignment-from-assumptions doesn't actually change anything in this test, even if I remove the alignment on the store or up the alignment from the assumption and alloca.

This revision is now accepted and ready to land.Mar 23 2020, 5:45 PM
This revision was automatically updated to reflect the committed changes.
DiamondLovesYou marked an inline comment as done.
alex-t added a subscriber: alex-t.Fri, Nov 24, 8:44 AM

This change does not fix a real problem but covers it instead.
Moreover, the test, which is assumed to crash without the change does not test anything as the @llvm.assume call has no bundles, and the
AlignmentFromAssumptionsPass::runImpl main loop never executes processAssumption.
Also, since the 615efc3ed59cd5073127e4f0709ae35e58a5dc4f [AlignmentFromAssumptions] Migrate tests to opaque pointers the test does not make sense at all as both
PtrSCEV and AASCEV are always just generic pointers.

It looks strange to me that nobody from the AMDGPU backend developers was invited to review this.

Herald added a project: Restricted Project. · View Herald TranscriptFri, Nov 24, 8:44 AM
Herald added a subscriber: arichardson. · View Herald Transcript
alex-t added inline comments.Fri, Nov 24, 8:47 AM
llvm/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
133

What will be if the PtrSCEV is 32bit but the AASCEV is 64bit?
You cannot zero extend a pointer type.