This remove the last uses of GlobalObject::getAlignment and marks it as deprecated.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 | This appears to be a change in behavior. AFAICT, previously used Var->getAlignment() could return alignment value or 0. Now it's value or 1. Is it intentional? |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 | The previous statement was constructing an llvm::Align from a value, and llvm::Align asserts when the provided value is 0. This means that it is undefined to pass the value 0. As far as LoadInst is concerned it can only accept valid alignments (i.e., powers of two => non zero). So you're right that it is not strictly NFC and that *Var->getAlign()would be a more rigorous transformation but I think that converting the 0 value to 1 moves us from UB to semantically valid code. I don't feel strongly about it though and I'm fine changing this to *Var->getAlign() to keep this patch NFC. WDYT? |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 | Enforcing alignment of 1 would potentially force us to generate overly conservative one byte at a time loads/stores. NewV = Var->getAlign().isAligned() ? llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false, Var->getAlign().value(), I) : llvm::LoadInst(Var->getType(), ManagedVar, "ld.managed", false, I); @yaxunl -- Sam, does it make sense? This seems to be largely HIP-specific. |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 | I think it should be just Var->getAlign() to allow propagating absent alignment. |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 |
That's interesting, because SelectionDAG::getLoad has many variants with MaybeAlign, but only one with Align. |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 | The documentation says that LoadInst alignment is optional so indeed it should accept a MaybeAlign instead of an Align. Then we can indeed simply use Var->getAlign(). |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 | Alignment is "optional" in textual IR for backward-compatibility/ease of use... but it's just a shortcut for specifying "use the ABI alignment of the value type". It isn't optional in memory. Maybe LangRef could be updated to make that a bit more clear. (See D77454.) We should consider doing something similar for globals, but at the time, I ran out of energy to try to deal with that; backend handling for globals with unspecified alignment is weird. |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 |
Thanks for reminding me about this. If it is 0 it should have caused an assertion. We can probably use getAlign().value() to keep the original asserting behaviour instead of silently using value 1. |
clang/lib/CodeGen/CGCUDANV.cpp | ||
---|---|---|
491 | I think MaybeAlign is ridiculous and we should just require alignments everywhere. It's never really optional, it's just hidden sometimes |
Thx @efriedma for reminding me of this.
I'll update the documentation and try to give a shot at removing MaybeAlign from GlobalObject.
Maybe*