summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2025-01-13 15:50:40 -0500
committerGitHub <noreply@github.com>2025-01-13 12:50:40 -0800
commit9a926058f45c7adfa569946b4f6b15a8772ac035 (patch)
treee98b715e1b8b49bc0227657cee4c8b1099e8d2bf /source
parent7bcc1a817ece5e708bd0fe2fd846cfe54c55ba64 (diff)
Don't initialize temp var for out parameters. (#6076)
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-autodiff-rev.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/source/slang/slang-ir-autodiff-rev.cpp b/source/slang/slang-ir-autodiff-rev.cpp
index 65ce69877..3237ba3b2 100644
--- a/source/slang/slang-ir-autodiff-rev.cpp
+++ b/source/slang/slang-ir-autodiff-rev.cpp
@@ -528,10 +528,12 @@ InstPair BackwardDiffTranscriber::transcribeFuncHeader(IRBuilder* inBuilder, IRF
// If primal parameter is mutable, we need to pass in a temp var.
auto tempVar = builder.emitVar(primalParamPtrType->getValueType());
- // We also need to setup the initial value of the temp var, otherwise
- // the temp var will be uninitialized which could cause undefined behavior
- // in the primal function.
- builder.emitStore(tempVar, primalArg);
+ // If the parameter is not a pure 'out' param, we also need to setup the initial
+ // value of the temp var, otherwise the temp var will be uninitialized which could
+ // cause undefined behavior in the primal function.
+ //
+ if (!as<IROutType>(primalParamType))
+ builder.emitStore(tempVar, primalArg);
primalArgs.add(tempVar);
}