Skip to content

Commit 34e800b

Browse files
committed
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.
1 parent fddfffe commit 34e800b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ static Instruction *convertNvvmIntrinsicToLlvm(InstCombiner &IC,
420420
// Returns nullopt if `II` is not one of the `isspacep` intrinsics.
421421
static std::optional<Instruction *>
422422
handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) {
423-
Value *Op0 = II.getArgOperand(0);
424423
// Returns true/false when we know the answer, nullopt otherwise.
425424
auto CheckASMatch = [](unsigned IID, unsigned AS) -> std::optional<bool> {
426425
if (AS == NVPTXAS::ADDRESS_SPACE_GENERIC ||
@@ -451,7 +450,7 @@ handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) {
451450
case Intrinsic::nvvm_isspacep_shared:
452451
case Intrinsic::nvvm_isspacep_shared_cluster:
453452
case Intrinsic::nvvm_isspacep_const: {
454-
auto *Ty = II.getType();
453+
Value *Op0 = II.getArgOperand(0);
455454
unsigned AS = Op0->getType()->getPointerAddressSpace();
456455
// Peek through ASC to generic AS.
457456
// TODO: we could dig deeper through both ASCs and GEPs.
@@ -460,7 +459,8 @@ handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) {
460459
AS = ASCO->getOperand(0)->getType()->getPointerAddressSpace();
461460

462461
if (std::optional<bool> Answer = CheckASMatch(IID, AS))
463-
return IC.replaceInstUsesWith(II, ConstantInt::get(Ty, *Answer));
462+
return IC.replaceInstUsesWith(II,
463+
ConstantInt::get(II.getType(), *Answer));
464464
return nullptr; // Don't know the answer, got to check at run time.
465465
}
466466
default:

0 commit comments

Comments
 (0)