This is an archive of the discontinued LLVM Phabricator instance.

Respect alignment when loading up a coerced function argument
ClosedPublic

Authored by uweigand on Jul 8 2015, 6:12 AM.

Details

Summary

Code in CGCall.cpp that loads up function arguments that need to be
coerced to a different type may in some cases ignore the fact that
the source of the argument is not naturally aligned. This may cause
incorrect code to be generated. In some places in CreateCoercedLoad,
we already have setAlignment calls to address this, but I ran into one
where it was missing, causing wrong code generation on SystemZ.

However, in that location, we do not actually know what alignment of
the source location we can rely on; the callers do not pass anything
to this routine. This is already an issue in other places in
CreateCoercedLoad; and the same problem exists for CreateCoercedStore.

To avoid pessimising code, and to fix the FIXMEs already in place,
this patch also adds an alignment argument to the CreateCoerced*
routines and uses it instead of forcing an alignment of 1. The
callers are changed to pass in the best information they have.

This actually requires changes in a number of existing test cases
since we now get better alignment in many places.

(Patch originally posted to cfe-commits; now moved to Phabricator
to simplify review.)

Diff Detail

Event Timeline

uweigand updated this revision to Diff 29259.Jul 8 2015, 6:12 AM
uweigand retitled this revision from to Respect alignment when loading up a coerced function argument .
uweigand updated this object.
uweigand added reviewers: rjmccall, rsmith, hfinkel.
uweigand added a subscriber: cfe-commits.
rjmccall edited edge metadata.Jul 8 2015, 5:03 PM

This is great, thank you for tackling it.

lib/CodeGen/CGCall.cpp
929

Missed this one.

988

Only DestPtr has alignment DestAlign. For the individual elements, you'll need to use alignmentAtOffset.

1012

Missed this one.

uweigand updated this revision to Diff 29341.Jul 9 2015, 9:23 AM
uweigand edited edge metadata.
uweigand marked 3 inline comments as done.

Addressed review comments:

  • Fixed struct element alignment
  • Fixed two missed loads/stores

LGTM, thanks!

This revision was automatically updated to reflect the committed changes.