[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:26:16 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:
Can I just replace the shift with a division by eight? this can be a constant expression as far as I'm aware.
https://github.com/llvm/llvm-project/pull/71815
More information about the llvm-commits
mailing list