Skip to content

Commit 4badd55

Browse files
committed
Fix Metal test failures
1 parent 6322903 commit 4badd55

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

source/slang/slang-ir-dce.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,15 @@ static bool eliminateRedundantTemporaryCopyInFunc(IRFunc* func)
553553

554554
auto loadedPtr = loadInst->getPtr();
555555

556+
// Check address space compatibility before optimization
557+
auto destPtrType = as<IRPtrTypeBase>(destPtr->getDataType());
558+
auto loadedPtrType = as<IRPtrTypeBase>(loadedPtr->getDataType());
559+
SLANG_ASSERT(destPtrType);
560+
SLANG_ASSERT(loadedPtrType);
561+
562+
if (destPtrType->getAddressSpace() != loadedPtrType->getAddressSpace())
563+
continue;
564+
556565
// Do not optimize loads from semantic parameters because some semantics have
557566
// builtin types that are vector types but pretend to be scalar types (e.g.,
558567
// SV_DispatchThreadID is used as 'int id' but maps to 'float3
@@ -631,8 +640,7 @@ static bool eliminateRedundantTemporaryCopyInFunc(IRFunc* func)
631640
goto unsafeToOptimize;
632641
}
633642

634-
// If we get here, all uses are safe to optimize
635-
// safeToOptimize:
643+
// If we get here, all uses are safe to optimize.
636644

637645
// Replace all uses of destPtr with loadedPtr
638646
destPtr->replaceUsesWith(loadedPtr);

0 commit comments

Comments
 (0)