From d7fccdc325c8ed4a1943bbb32faa92057d2339ba Mon Sep 17 00:00:00 2001 From: Billy Moses Date: Sat, 28 Dec 2024 12:42:28 -0500 Subject: [PATCH] slice activity analysis --- enzyme/Enzyme/ActivityAnalysis.cpp | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/enzyme/Enzyme/ActivityAnalysis.cpp b/enzyme/Enzyme/ActivityAnalysis.cpp index cedaa1d19c3..9e80587a52d 100644 --- a/enzyme/Enzyme/ActivityAnalysis.cpp +++ b/enzyme/Enzyme/ActivityAnalysis.cpp @@ -579,6 +579,11 @@ bool ActivityAnalyzer::isFunctionArgumentConstant(CallInst *CI, Value *val) { if (Name == "jl_reshape_array" || Name == "ijl_reshape_array") return val != CI->getArgOperand(1); + // Only the 0-th arg impacts activity + if (Name == "jl_genericmemory_copy_slice" || + Name == "ijl_genericmemory_copy_slice") + return val != CI->getArgOperand(0); + // Allocations, deallocations, and c++ guards don't impact the activity // of arguments if (isAllocationFunction(Name, TLI) || isDeallocationFunction(Name, TLI)) @@ -660,6 +665,13 @@ static inline void propagateArgumentInformation( return; } + // Only the 0-th arg impacts activity + if (Name == "jl_genericmemory_copy_slice" || + Name == "ijl_genericmemory_copy_slice") { + propagateFromOperand(CI.getArgOperand(1)); + return; + } + // Only the 1-th arg impacts activity if (Name == "jl_reshape_array" || Name == "ijl_reshape_array") { propagateFromOperand(CI.getArgOperand(1)); @@ -1583,6 +1595,29 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) { return true; } + if (funcName == "jl_genericmemory_copy_slice" || + funcName == "ijl_genericmemory_copy_slice") { + if (directions == UP) { + if (isConstantValue(TR, op->getArgOperand(0))) { + InsertConstantValue(TR, Val); + return true; + } + } else { + if (UpHypothesis->isConstantValue(TR, op->getArgOperand(0))) { + InsertConstantValue(TR, Val); + insertConstantsFrom(TR, *UpHypothesis); + return true; + } + } + if (EnzymeEnableRecursiveHypotheses) { + ReEvaluateValueIfInactiveValue[op->getArgOperand(0)].insert(Val); + if (TmpOrig != Val) { + ReEvaluateValueIfInactiveValue[op->getArgOperand(0)].insert( + TmpOrig); + } + } + } + // If requesting empty unknown functions to be considered inactive, // abide by those rules if (called && EnzymeEmptyFnInactive && called->empty() &&