Skip to content

Commit 711ed6e

Browse files
authored
Revert "[SPIR-V][OpaquePointers] Temporary workaround for IGC issue (#10407)" (#16586)
This reverts commit aaa2e13. As it was a workaround, and the GPU drivers are updated in CI now, we can safely remove it to align back the translator's code base to Khronos.
1 parent c9b9b56 commit 711ed6e

File tree

1 file changed

+0
-65
lines changed

1 file changed

+0
-65
lines changed

llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -434,65 +434,6 @@ bool SPIRVRegularizeLLVMBase::runRegularizeLLVM(Module &Module) {
434434
return true;
435435
}
436436

437-
// This is a temporary workaround to deal with a graphics driver failure not
438-
// able to support the typed pointer reverse translation of
439-
// getelementptr i8, ptr @__spirv_Builtin* patterns. This replaces such
440-
// accesses with getelementptr i32, ptr @__spirv_Builtin instead.
441-
static void simplifyBuiltinVarAccesses(GlobalValue *GV) {
442-
// IGC only supports:
443-
// load GV
444-
// load (addrspacecast GV)
445-
// load (gep (addrspacecast GV))
446-
// load (gep GV)
447-
// Opaque pointers will cause the optimizer to use i8 geps, or to remove
448-
// 0-index geps entirely (adding bitcasts to the result). Restore these to
449-
// avoid bitcasts in the resulting IR.
450-
Type *Ty = GV->getValueType();
451-
Type *ScalarTy = Ty->getScalarType();
452-
SmallVector<Value *, 4> Users;
453-
for (auto User : GV->users()) {
454-
if (auto *LI = dyn_cast<LoadInst>(User)) {
455-
if (LI->getType() != Ty)
456-
Users.push_back(LI);
457-
} else if (auto *GEP = dyn_cast<GEPOperator>(User)) {
458-
if (GEP->getSourceElementType() != Ty)
459-
Users.push_back(GEP);
460-
}
461-
}
462-
463-
Type *Int32Ty = Type::getInt32Ty(GV->getContext());
464-
auto GetGep = [&](unsigned Offset,
465-
std::optional<ConstantRange> InRange = std::nullopt) {
466-
llvm::ConstantRange GepInRange(llvm::APInt(32, -((signed)Offset), true),
467-
llvm::APInt(32, Offset, true));
468-
if (InRange)
469-
GepInRange = *InRange;
470-
return ConstantExpr::getGetElementPtr(
471-
Ty, GV,
472-
ArrayRef<Constant *>(
473-
{ConstantInt::get(Int32Ty, 0), ConstantInt::get(Int32Ty, Offset)}),
474-
true, GepInRange);
475-
};
476-
477-
const DataLayout &DL = GV->getParent()->getDataLayout();
478-
for (auto *User : Users) {
479-
if (auto *LI = dyn_cast<LoadInst>(User)) {
480-
LI->setOperand(0, GetGep(0));
481-
} else if (auto *GEP = dyn_cast<GEPOperator>(User)) {
482-
APInt Offset(64, 0);
483-
GEP->accumulateConstantOffset(DL, Offset);
484-
APInt Index;
485-
uint64_t Remainder;
486-
APInt::udivrem(Offset, ScalarTy->getScalarSizeInBits() / 8, Index,
487-
Remainder);
488-
assert(Remainder == 0 && "Cannot handle misaligned access to builtins");
489-
GEP->replaceAllUsesWith(GetGep(Index.getZExtValue(), GEP->getInRange()));
490-
if (auto *Inst = dyn_cast<Instruction>(GEP))
491-
Inst->eraseFromParent();
492-
}
493-
}
494-
}
495-
496437
namespace {
497438
void regularizeWithOverflowInstrinsics(StringRef MangledName, CallInst *Call,
498439
Module *M,
@@ -642,12 +583,6 @@ bool SPIRVRegularizeLLVMBase::regularize() {
642583
expandSYCLTypeUsing(M);
643584
cleanupConversionToNonStdIntegers(M);
644585

645-
for (auto &GV : M->globals()) {
646-
SPIRVBuiltinVariableKind Kind;
647-
if (isSPIRVBuiltinVariable(&GV, &Kind))
648-
simplifyBuiltinVarAccesses(&GV);
649-
}
650-
651586
// Kernels called by other kernels
652587
std::vector<Function *> CalledKernels;
653588
for (auto I = M->begin(), E = M->end(); I != E;) {

0 commit comments

Comments
 (0)