Skip to content

Commit 04e876e

Browse files
authored
Revert "[NVPTX] instcombine known pointer AS checks." (#114319)
Reverts #112964 Crashes MLIR: https://lab.llvm.org/buildbot/#/builders/138/builds/5665
1 parent d043670 commit 04e876e

File tree

4 files changed

+13
-372
lines changed

4 files changed

+13
-372
lines changed

llvm/include/llvm/Support/NVPTXAddrSpace.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXBaseInfo.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
1616
#ifndef LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXBASEINFO_H
1717
#define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXBASEINFO_H
1818

19-
#include "llvm/Support/NVPTXAddrSpace.h"
2019
namespace llvm {
2120

22-
using namespace NVPTXAS;
21+
enum AddressSpace {
22+
ADDRESS_SPACE_GENERIC = 0,
23+
ADDRESS_SPACE_GLOBAL = 1,
24+
ADDRESS_SPACE_SHARED = 3,
25+
ADDRESS_SPACE_CONST = 4,
26+
ADDRESS_SPACE_LOCAL = 5,
27+
28+
// NVVM Internal
29+
ADDRESS_SPACE_PARAM = 101
30+
};
2331

2432
namespace NVPTXII {
2533
enum {

llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
#include "llvm/CodeGen/CostTable.h"
1616
#include "llvm/CodeGen/TargetLowering.h"
1717
#include "llvm/IR/Constants.h"
18-
#include "llvm/IR/IntrinsicInst.h"
1918
#include "llvm/IR/Intrinsics.h"
2019
#include "llvm/IR/IntrinsicsNVPTX.h"
2120
#include "llvm/IR/Value.h"
2221
#include "llvm/Support/Casting.h"
23-
#include "llvm/Support/ErrorHandling.h"
2422
#include "llvm/Transforms/InstCombine/InstCombiner.h"
2523
#include <optional>
2624
using namespace llvm;
@@ -119,8 +117,7 @@ bool NVPTXTTIImpl::isSourceOfDivergence(const Value *V) {
119117
}
120118

121119
// Convert NVVM intrinsics to target-generic LLVM code where possible.
122-
static Instruction *convertNvvmIntrinsicToLlvm(InstCombiner &IC,
123-
IntrinsicInst *II) {
120+
static Instruction *simplifyNvvmIntrinsic(IntrinsicInst *II, InstCombiner &IC) {
124121
// Each NVVM intrinsic we can simplify can be replaced with one of:
125122
//
126123
// * an LLVM intrinsic,
@@ -416,65 +413,11 @@ static Instruction *convertNvvmIntrinsicToLlvm(InstCombiner &IC,
416413
llvm_unreachable("All SpecialCase enumerators should be handled in switch.");
417414
}
418415

419-
// Returns an instruction pointer (may be nullptr if we do not know the answer).
420-
// Returns nullopt if `II` is not one of the `isspacep` intrinsics.
421-
static std::optional<Instruction *>
422-
handleSpaceCheckIntrinsics(InstCombiner &IC, IntrinsicInst &II) {
423-
Value *Op0 = II.getArgOperand(0);
424-
// Returns true/false when we know the answer, nullopt otherwise.
425-
auto CheckASMatch = [](unsigned IID, unsigned AS) -> std::optional<bool> {
426-
if (AS == NVPTXAS::ADDRESS_SPACE_GENERIC ||
427-
AS == NVPTXAS::ADDRESS_SPACE_PARAM)
428-
return std::nullopt; // Got to check at run-time.
429-
switch (IID) {
430-
case Intrinsic::nvvm_isspacep_global:
431-
return AS == NVPTXAS::ADDRESS_SPACE_GLOBAL;
432-
case Intrinsic::nvvm_isspacep_local:
433-
return AS == NVPTXAS::ADDRESS_SPACE_LOCAL;
434-
case Intrinsic::nvvm_isspacep_shared:
435-
return AS == NVPTXAS::ADDRESS_SPACE_SHARED;
436-
case Intrinsic::nvvm_isspacep_shared_cluster:
437-
// We can't tell shared from shared_cluster at compile time from AS alone,
438-
// but it can't be either is AS is not shared.
439-
return AS == NVPTXAS::ADDRESS_SPACE_SHARED ? std::nullopt
440-
: std::optional{false};
441-
case Intrinsic::nvvm_isspacep_const:
442-
return AS == NVPTXAS::ADDRESS_SPACE_CONST;
443-
default:
444-
llvm_unreachable("Unexpected intrinsic");
445-
}
446-
};
447-
448-
switch (auto IID = II.getIntrinsicID()) {
449-
case Intrinsic::nvvm_isspacep_global:
450-
case Intrinsic::nvvm_isspacep_local:
451-
case Intrinsic::nvvm_isspacep_shared:
452-
case Intrinsic::nvvm_isspacep_shared_cluster:
453-
case Intrinsic::nvvm_isspacep_const: {
454-
auto *Ty = II.getType();
455-
unsigned AS = Op0->getType()->getPointerAddressSpace();
456-
// Peek through ASC to generic AS.
457-
// TODO: we could dig deeper through both ASCs and GEPs.
458-
if (AS == NVPTXAS::ADDRESS_SPACE_GENERIC)
459-
if (auto *ASCO = dyn_cast<AddrSpaceCastOperator>(Op0))
460-
AS = ASCO->getOperand(0)->getType()->getPointerAddressSpace();
461-
462-
if (std::optional<bool> Answer = CheckASMatch(IID, AS))
463-
return IC.replaceInstUsesWith(II, ConstantInt::get(Ty, *Answer));
464-
return nullptr; // Don't know the answer, got to check at run time.
465-
}
466-
default:
467-
return std::nullopt;
468-
}
469-
}
470-
471416
std::optional<Instruction *>
472417
NVPTXTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
473-
if (std::optional<Instruction *> I = handleSpaceCheckIntrinsics(IC, II))
474-
return *I;
475-
if (Instruction *I = convertNvvmIntrinsicToLlvm(IC, &II))
418+
if (Instruction *I = simplifyNvvmIntrinsic(&II, IC)) {
476419
return I;
477-
420+
}
478421
return std::nullopt;
479422
}
480423

0 commit comments

Comments
 (0)