Failed to deduce type of memset with optimization level > 0
Hi team,
I get the following error as long as I set a non-zero optimization level:
/root/.freetensor/BDqwP0/run.cpp:83:48: error: Enzyme: failed to deduce type of memset call void @llvm.memset.p0i8.i64(i8* nonnull align 16 dereferenceable(40000) getelementptr inbounds ([304640 x i8], [304640 x i8]* @_ZZ3runE13__sharedStack, i64 0, i64 160384), i8 0, i64 40000, i1 false) #12, !dbg !1710
_y__4[((_i__31 * 5) + _i__32)] = 0;
^
Here, _y__4 is defined as auto &&_y__4 = ((double*)(&__sharedStack[160384]));, and __sharedStack is a raw buffer, which is always cast to pointer-to-double to use.
This zeroing statement is in a loop. I guess it is optimized to be a integer memset with optimization levels, and Enzyme failed to recognize it.
The full error message is attached, because it has reached the limit of GitHub comments. log.txt
Sorry I don't have a minimal reproduction. I can attach /tmp/run-11a9c9.cpp and /tmp/run-11a9c9.sh prepared by Clang if you need.
Tested with Enzyme 0.0.66 and Clang 12, with ClangEnzyme.
Thanks in advance.
Yeah a reproducer would be helpful. As one hint, it seems to not be terribly happy about: _ZZ3runE13__sharedStack. Maybe mark it as inactive?
Regardless you probably want to have all differentiable variables passed as arguments rather than globals
Sorry, I found it was my mistake. Although _ZZ3runE13__sharedStack is a local variable, but I mistakenly mark it as static, so it became a global variable.
Closing this issue, and it would be great to see if the compiler can warn me about this.
Sorry but after I changed it to static, the "failed to deduce type of memset" message still occurs. This time _ZZ3runE13__sharedStack is a genuine local variable. Besides, it is not inactive, because gradient actually flows by this variable.
_ZZ3runE13__sharedStack is actually a holder array for other variables I use. Other variables are slices of this array.
See the log and the reproducer: log.txt run-4ab46e.cpp.txt run-4ab46e.sh.txt Please change *.cpp.txt to *.txt, and *.sh.txt to *.txt. It was because GitHub don't allow uploading .cpp and .sh files.
I'm having some issues reproducing this. Can you make a version which errors in the Enzyme Compiler Explorer? https://enzyme.mit.edu/explorer/