This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP][IR] Set correct alignment for internal variables
ClosedPublic

Authored by erjin on Aug 3 2023, 2:37 PM.

Details

Summary

OpenMP runtime functions assume the pointers are aligned to sizeof(pointer), but it is being aligned incorrectly. Fix with the proper alignment in the IR builder.

Diff Detail

Event Timeline

erjin created this revision.Aug 3 2023, 2:37 PM
erjin requested review of this revision.Aug 3 2023, 2:37 PM

It looks this issue will not just affect this single variable. It needs to be fixed in getOrCreateInternalVariable.

erjin updated this revision to Diff 547100.Aug 3 2023, 9:36 PM
erjin retitled this revision from [OpenMP][IR] Set correct alignment for critical region lock to [OpenMP][IR] Set correct alignment for internal variables.

Thanks for the review! I have made changes based on the comment. Specify the alignment while making these internal variables.

gchatelet added inline comments.Aug 4 2023, 12:08 AM
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
4496–4499

You can go for the slightly more readable version below

const DataLayout &DL = M.getDataLayout();
const llvm::Align TypeAlign = DL.getABITypeAlign(Ty);
const llvm::Align PtrAlign = DL.getPointerABIAlignment(AddressSpace);
GV->setAlignment(std::max(TypeAlign, PtrAlign));
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
2753–2754

GV->getAlignment() should disappear. Can you use the following lines instead?

if(const llvm::MaybeAlign Alignment = GV->getAlign()) {
  EXPECT_EQ(*Alignment, PtrAlign);
}
erjin updated this revision to Diff 547282.Aug 4 2023, 11:21 AM

Thanks for the suggestions. Made changes based on them.

I think the diff is based on your previous version instead of trunk. Can you rebase it?

erjin updated this revision to Diff 547306.Aug 4 2023, 12:12 PM

Rebased. Thanks

The parent version for clang/lib/CodeGen/CGOpenMPRuntime.cpp is still not right.

erjin updated this revision to Diff 548344.EditedAug 8 2023, 1:51 PM

Rebased with arc. Hope it works now

Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 1:51 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Aug 10 2023, 3:30 PM
This revision was automatically updated to reflect the committed changes.