Skip to content

Commit

Permalink
Fix operator signedness mismatch issue
Browse files Browse the repository at this point in the history
This helps to address issue shader-slang#5606.
  • Loading branch information
aleino-nv committed Nov 27, 2024
1 parent 0b374aa commit c44786b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions source/slang/slang-ir-wgsl-legalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,29 @@ struct LegalizeWGSLEntryPointContext
inst->getOperand(0));
builder.replaceOperand(inst->getOperands(), newLhs);
}
else if (
isIntegralType(inst->getOperand(0)->getDataType()) &&
isIntegralType(inst->getOperand(1)->getDataType()))
{
// If integer operands differ in signedness, convert the signed one to unsigned.
// We're assuming that the cases where this is bad have already been caught by
// common validation checks.
IntInfo opIntInfo[2] = {
getIntTypeInfo(inst->getOperand(0)->getDataType()),
getIntTypeInfo(inst->getOperand(1)->getDataType())
};
if (opIntInfo[0].isSigned != opIntInfo[1].isSigned)
{
int signedOpIndex = (int)opIntInfo[1].isSigned;
opIntInfo[signedOpIndex].isSigned = false;
IRBuilder builder(inst);
builder.setInsertBefore(inst);
auto newOp = builder.emitCast(
builder.getType(getIntTypeOpFromInfo(opIntInfo[signedOpIndex])),
inst->getOperand(signedOpIndex));
builder.replaceOperand(inst->getOperands() + signedOpIndex, newOp);
}
}
}

void processInst(IRInst* inst)
Expand Down

0 comments on commit c44786b

Please sign in to comment.