From 34e800b7b6eceacc6e32c942d145c5ff6aa5192c Mon Sep 17 00:00:00 2001 From: Artem Belevich Date: Wed, 30 Oct 2024 16:01:05 -0700 Subject: [PATCH] Do not touch intrinsic operands until we've checked intrinsic ID. Fixes the crash in MLIR and CUDA compilation when they handle some other nvvm intrinsic w/o arguments. --- llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp index 31087a0054e9fa..3507573df1869f 100644 --- a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp @@ -420,7 +420,6 @@ static Instruction *convertNvvmIntrinsicToLlvm(InstCombiner &IC, // Returns nullopt if `II` is not one of the `isspacep` intrinsics. static std::optional handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) { - Value *Op0 = II.getArgOperand(0); // Returns true/false when we know the answer, nullopt otherwise. auto CheckASMatch = [](unsigned IID, unsigned AS) -> std::optional { if (AS == NVPTXAS::ADDRESS_SPACE_GENERIC || @@ -451,7 +450,7 @@ handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) { case Intrinsic::nvvm_isspacep_shared: case Intrinsic::nvvm_isspacep_shared_cluster: case Intrinsic::nvvm_isspacep_const: { - auto *Ty = II.getType(); + Value *Op0 = II.getArgOperand(0); unsigned AS = Op0->getType()->getPointerAddressSpace(); // Peek through ASC to generic AS. // TODO: we could dig deeper through both ASCs and GEPs. @@ -460,7 +459,8 @@ handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) { AS = ASCO->getOperand(0)->getType()->getPointerAddressSpace(); if (std::optional Answer = CheckASMatch(IID, AS)) - return IC.replaceInstUsesWith(II, ConstantInt::get(Ty, *Answer)); + return IC.replaceInstUsesWith(II, + ConstantInt::get(II.getType(), *Answer)); return nullptr; // Don't know the answer, got to check at run time. } default: