Skip to content

Commit 1ed7d29

Browse files
committed
Fix issue with specialization using arithmetic expressions
1 parent 7bcc1a8 commit 1ed7d29

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

source/slang/slang-ir-specialize.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,42 @@ struct SpecializationContext
7171
module->getContainerPool().free(&cleanInsts);
7272
}
7373

74+
bool isUnsimplifiedArithmeticInst(IRInst* inst)
75+
{
76+
switch (inst->getOp())
77+
{
78+
case kIROp_Add:
79+
case kIROp_Sub:
80+
case kIROp_Mul:
81+
case kIROp_Div:
82+
case kIROp_Neg:
83+
case kIROp_Not:
84+
case kIROp_Eql:
85+
case kIROp_Neq:
86+
case kIROp_Leq:
87+
case kIROp_Geq:
88+
case kIROp_Less:
89+
case kIROp_IRem:
90+
case kIROp_FRem:
91+
case kIROp_Greater:
92+
case kIROp_Lsh:
93+
case kIROp_Rsh:
94+
case kIROp_BitAnd:
95+
case kIROp_BitOr:
96+
case kIROp_BitXor:
97+
case kIROp_BitNot:
98+
case kIROp_BitCast:
99+
case kIROp_CastIntToFloat:
100+
case kIROp_CastFloatToInt:
101+
case kIROp_IntCast:
102+
case kIROp_FloatCast:
103+
case kIROp_Select:
104+
return true;
105+
default:
106+
return false;
107+
}
108+
}
109+
74110
// An instruction is then fully specialized if and only
75111
// if it is in our set.
76112
//
@@ -133,6 +169,14 @@ struct SpecializationContext
133169
return areAllOperandsFullySpecialized(inst);
134170
}
135171

172+
if (isUnsimplifiedArithmeticInst(inst))
173+
{
174+
// For arithmetic insts, we want to wait for simplification before specialization,
175+
// since different insts can simplify to the same value.
176+
//
177+
return false;
178+
}
179+
136180
// The default case is that a global value is always specialized.
137181
if (inst->getParent() == module->getModuleInst())
138182
{
@@ -1092,6 +1136,7 @@ struct SpecializationContext
10921136
{
10931137
this->changed = true;
10941138
eliminateDeadCode(module->getModuleInst());
1139+
applySparseConditionalConstantPropagationForGlobalScope(this->module, this->sink);
10951140
}
10961141

10971142
// Once the work list has gone dry, we should have the invariant

source/slang/slang.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,8 @@ DeclRef<Decl> Linkage::specializeWithArgTypes(
14931493
DiagnosticSink* sink)
14941494
{
14951495
SemanticsVisitor visitor(getSemanticsForReflection());
1496-
visitor = visitor.withSink(sink);
1496+
SemanticsVisitor::ExprLocalScope scope;
1497+
visitor = visitor.withSink(sink).withExprLocalScope(&scope);
14971498

14981499
SLANG_AST_BUILDER_RAII(getASTBuilder());
14991500

0 commit comments

Comments
 (0)