Skip to content

Commit

Permalink
Do not touch intrinsic operands until we've checked intrinsic ID.
Browse files Browse the repository at this point in the history
Fixes the crash in MLIR and CUDA compilation when they handle some other nvvm intrinsic w/o arguments.
  • Loading branch information
Artem-B committed Oct 30, 2024
1 parent fddfffe commit 34e800b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ static Instruction *convertNvvmIntrinsicToLlvm(InstCombiner &IC,
// Returns nullopt if `II` is not one of the `isspacep` intrinsics.
static std::optional<Instruction *>
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<bool> {
if (AS == NVPTXAS::ADDRESS_SPACE_GENERIC ||
Expand Down Expand Up @@ -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.
Expand All @@ -460,7 +459,8 @@ handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) {
AS = ASCO->getOperand(0)->getType()->getPointerAddressSpace();

if (std::optional<bool> 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:
Expand Down

0 comments on commit 34e800b

Please sign in to comment.