summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-01-09 12:41:07 -0800
committerGitHub <noreply@github.com>2024-01-09 12:41:07 -0800
commit8dd04c8730327d7dc2fd29b43b8566fabbc3aa2c (patch)
treefeeb609fd142d1b404f16f8ecded37fb12655e75 /source
parent69f3d7917d66c370ff87832dbbe2d05c5795d5ce (diff)
Fix funcs w/ buffer load being treated as readnone. (#3441)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-propagate-func-properties.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/source/slang/slang-ir-propagate-func-properties.cpp b/source/slang/slang-ir-propagate-func-properties.cpp
index df7869205..f186a3a57 100644
--- a/source/slang/slang-ir-propagate-func-properties.cpp
+++ b/source/slang/slang-ir-propagate-func-properties.cpp
@@ -14,6 +14,22 @@ public:
virtual bool propagate(IRBuilder& builder, IRFunc* func) = 0;
};
+static bool isResourceLoad(IROp op)
+{
+ switch (op)
+ {
+ case kIROp_ImageLoad:
+ case kIROp_StructuredBufferLoad:
+ case kIROp_ByteAddressBufferLoad:
+ case kIROp_StructuredBufferLoadStatus:
+ case kIROp_RWStructuredBufferLoad:
+ case kIROp_RWStructuredBufferLoadStatus:
+ return true;
+ default:
+ return false;
+ }
+}
+
static bool isKnownOpCodeWithSideEffect(IROp op)
{
switch (op)
@@ -54,7 +70,7 @@ public:
virtual bool propagate(IRBuilder& builder, IRFunc* f) override
{
- bool hasSideEffectCall = false;
+ bool hasReadNoneCall = false;
for (auto block : f->getBlocks())
{
for (auto inst : block->getChildren())
@@ -62,11 +78,14 @@ public:
// Is this inst known to not have global side effect/analyzable?
if (!isKnownOpCodeWithSideEffect(inst->getOp()))
{
- if (inst->mightHaveSideEffects())
+ if (inst->mightHaveSideEffects() || isResourceLoad(inst->getOp()))
{
- // We have a inst that has side effect and is not understood by this method.
+ // We have a inst that has side effect that is not understood by this method,
// e.g. bufferStore, discard, etc.
- hasSideEffectCall = true;
+ // or we are seeing a resource load.
+ // These operations are not movable or removable,
+ // and should not be treated as ReadNone.
+ hasReadNoneCall = true;
break;
}
}
@@ -79,12 +98,12 @@ public:
default:
// We are calling an unknown function, so we have to assume
// there are side effects in the call.
- hasSideEffectCall = true;
+ hasReadNoneCall = true;
break;
case kIROp_Func:
if (!callee->findDecoration<IRReadNoneDecoration>())
{
- hasSideEffectCall = true;
+ hasReadNoneCall = true;
break;
}
}
@@ -102,16 +121,16 @@ public:
continue;
if (isGlobalOrUnknownMutableAddress(f, operand))
{
- hasSideEffectCall = true;
+ hasReadNoneCall = true;
break;
}
break;
}
}
- if (hasSideEffectCall)
+ if (hasReadNoneCall)
break;
}
- if (!hasSideEffectCall)
+ if (!hasReadNoneCall)
{
builder.addDecoration(f, kIROp_ReadNoneDecoration);
return true;