Fix an assert on cbuffer loads of bool vectors. (#2104)

After loading a vector from a cbuffer, we attempt moving the debug info upstream, to the individually loaded elements, assuming that they got converted into a vector by a sequence of insertelement instructions. This is not the case for bool vectors, because the insertelement sequence will be followed by a mem-to-reg conversion. Made the code more resilient to such unexpected patterns (better to lose debug info than to crash compilation).
This commit is contained in:
Tristan Labelle 2019-04-04 11:44:33 -07:00 коммит произвёл GitHub
Родитель 75df1b1436
Коммит ada42260b2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -98,7 +98,7 @@ namespace dxilutil {
unsigned numOperands);
bool SimplifyTrivialPHIs(llvm::BasicBlock *BB);
void MigrateDebugValue(llvm::Value *Old, llvm::Value *New);
void ScatterDebugValueToVectorElements(llvm::Value *Val);
void TryScatterDebugValueToVectorElements(llvm::Value *Val);
std::unique_ptr<llvm::Module> LoadModuleFromBitcode(llvm::StringRef BC,
llvm::LLVMContext &Ctx, std::string &DiagStr);
std::unique_ptr<llvm::Module> LoadModuleFromBitcode(llvm::MemoryBuffer *MB,

Просмотреть файл

@ -363,8 +363,9 @@ void MigrateDebugValue(Value *Old, Value *New) {
// If we just keep the debug info on the recomposed vector,
// we will lose it when we break it apart again during later
// optimization stages.
void ScatterDebugValueToVectorElements(Value *Val) {
DXASSERT(isa<InsertElementInst>(Val), "Should be a newly gathered vector.");
void TryScatterDebugValueToVectorElements(Value *Val) {
if (!isa<InsertElementInst>(Val) || !Val->getType()->isVectorTy()) return;
DbgValueInst *VecDbgValInst = FindDbgValueInst(Val);
if (VecDbgValInst == nullptr) return;

Просмотреть файл

@ -5500,7 +5500,7 @@ void TranslateCBAddressUserLegacy(Instruction *user, Value *handle,
Value *newLd = TranslateConstBufMatLdLegacy(
MatTy, handle, legacyIdx, colMajor, hlslOP, /*memElemRepr*/false, DL, Builder);
CI->replaceAllUsesWith(newLd);
dxilutil::ScatterDebugValueToVectorElements(newLd);
dxilutil::TryScatterDebugValueToVectorElements(newLd);
CI->eraseFromParent();
} else if (group == HLOpcodeGroup::HLSubscript) {
HLSubscriptOpcode subOp = static_cast<HLSubscriptOpcode>(opcode);
@ -5669,7 +5669,7 @@ void TranslateCBAddressUserLegacy(Instruction *user, Value *handle,
hlslOP, Builder);
ldInst->replaceAllUsesWith(newLd);
if (Ty->isVectorTy()) dxilutil::ScatterDebugValueToVectorElements(newLd);
dxilutil::TryScatterDebugValueToVectorElements(newLd);
ldInst->eraseFromParent();
} else if (BitCastInst *BCI = dyn_cast<BitCastInst>(user)) {
for (auto it = BCI->user_begin(); it != BCI->user_end(); ) {

Просмотреть файл

@ -630,7 +630,7 @@ void replaceDirectInputParameter(Value *param, Function *loadInput,
param->replaceAllUsesWith(newVec);
// THe individual loadInputs are the authoritative source of values for the vector.
dxilutil::ScatterDebugValueToVectorElements(newVec);
dxilutil::TryScatterDebugValueToVectorElements(newVec);
} else if (!Ty->isArrayTy() && !HLMatrixType::isa(Ty)) {
DXASSERT(cols == 1, "only support scalar here");
Value *colIdx = hlslOP->GetU8Const(0);