summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheresa Foley <10618364+tangent-vector@users.noreply.github.com>2022-03-01 10:34:07 -0800
committerGitHub <noreply@github.com>2022-03-01 10:34:07 -0800
commit71fc1d28c8ff171c09f7a4c97d55dfbc4d0985e3 (patch)
tree38a83a9a117fef0a45a7628682d186664f24bb67
parente6c9625e0f0d5d9703451fd2ebb8b206d210009c (diff)
Fix folding of no-arg constructs in SCCP pass (#2148)
-rw-r--r--source/slang/slang-ir-sccp.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/source/slang/slang-ir-sccp.cpp b/source/slang/slang-ir-sccp.cpp
index 463de29ca..28f262c1a 100644
--- a/source/slang/slang-ir-sccp.cpp
+++ b/source/slang/slang-ir-sccp.cpp
@@ -373,6 +373,37 @@ struct SCCPContext
return LatticeVal::getConstant(resultVal);
}
+ LatticeVal evalDefaultConstruct(IRType* type)
+ {
+ IRInst* resultVal = nullptr;
+ switch (type->getOp())
+ {
+ case kIROp_Int8Type:
+ case kIROp_Int16Type:
+ case kIROp_IntType:
+ case kIROp_Int64Type:
+ case kIROp_UInt8Type:
+ case kIROp_UInt16Type:
+ case kIROp_UIntType:
+ case kIROp_UInt64Type:
+ resultVal = getBuilder()->getIntValue(type, (IRIntegerValue)0);
+ break;
+
+ case kIROp_FloatType:
+ case kIROp_DoubleType:
+ case kIROp_HalfType:
+ resultVal = getBuilder()->getFloatValue(type, (IRFloatingPointValue)0.0);
+ break;
+
+ case kIROp_BoolType:
+ resultVal = getBuilder()->getBoolValue(false);
+ break;
+ }
+ if (!resultVal)
+ return LatticeVal::getAny();
+ return LatticeVal::getConstant(resultVal);
+ }
+
template<typename TIntFunc, typename TFloatFunc>
LatticeVal evalBinaryImpl(
IRType* type,
@@ -800,7 +831,17 @@ struct SCCPContext
switch (inst->getOp())
{
case kIROp_Construct:
- return evalConstruct(inst->getDataType(), getLatticeVal(inst->getOperand(0)));
+ switch (inst->getOperandCount())
+ {
+ case 0:
+ return evalDefaultConstruct(inst->getDataType());
+
+ case 1:
+ return evalConstruct(inst->getDataType(), getLatticeVal(inst->getOperand(0)));
+
+ default:
+ return LatticeVal::getAny();
+ }
case kIROp_Add:
return evalAdd(
inst->getDataType(),