[llvm] [AMDGPU] Call the `FINI_ARRAY` destructors in the correct order (PR #71815)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 10 08:09:15 PST 2023
================
@@ -96,15 +105,39 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
// for now we just call them with no arguments.
auto *CallBackTy = FunctionType::get(IRB.getVoidTy(), {});
- IRB.CreateCondBr(IRB.CreateICmpNE(Begin, End), LoopBB, ExitBB);
+ Constant *Start = Begin;
+ Constant *Stop = End;
+ // The destructor array must be called in reverse order. Get a constant
+ // expression to the end of the array and iterate backwards instead.
+ if (!IsCtor) {
+ Type *Int64Ty = IntegerType::getInt64Ty(C);
+ auto *Offset = ConstantExpr::getSub(
+ ConstantExpr::getAShr(
+ ConstantExpr::getSub(ConstantExpr::getPtrToInt(End, Int64Ty),
+ ConstantExpr::getPtrToInt(Begin, Int64Ty)),
+ ConstantInt::get(Int64Ty, 3)),
+ ConstantInt::get(Int64Ty, 1));
+ Start = ConstantExpr::getGetElementPtr(
+ ArrayType::get(IRB.getPtrTy(), 0), Begin,
+ ArrayRef<Constant *>({ConstantInt::get(Int64Ty, 0), Offset}),
+ /*InBounds=*/true);
+ Stop = Begin;
----------------
jhuber6 wrote:
The patch was functional and wasn't breaking any tests, if it's a matter of improving it would've been much easier to adjust it on top of this.
What is the issue with using ConstantExpr / ASHR here? There's no deprecation warnings or anything on the implementation. These can be constant expressions and we get the exact same code from `clang` if you compile it, see https://godbolt.org/z/Mzvhas451. So I'm confused as to what's wrong here. I guess we need to fix this in `clang` as well?
https://github.com/llvm/llvm-project/pull/71815
More information about the llvm-commits
mailing list