pcwang-thead added a comment. In D126461#3565305 <https://reviews.llvm.org/D126461#3565305>, @khchen wrote:
>> Store to null will be changed to unreachable, so all instructions after >> vleff intrinsic call will be deleted and it causes runtime errors. If >> destination to store is null, we won't extract and store the new vl. > > > >> Yes, but only for vleff instructions, since it has two outputs actually. And >> this behavior is compatible with GCC. If necessary, I will propose it to >> rvv-intrinsic-doc. > > Compiling with -O0, I didn't see this behavior, so are you trying to make the > optimized code behavior is compatible with GCC? > In addition, it seems this behavior also exist in scalar code, do we also > need to make the scalar result is compatible with GCC? Store to nullptr is UB and it seems that LLVM and GCC have different behavior. As shown in https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/Local.cpp#L2317, LLVM (`simplifycfg` in particular) will turn stores to nullptr into unreachable. When compiling with -O0, no optimization is done, so we can't see this behavior. What I am doing in this patch is not making store to nullptr a defined behavior, but changing the way to store the new vl in vleff intrinsics (only do it if destination to store is not null). Before: new_vl = vleff(...) *dst = new_vl; Now: new_vl = vleff(...) if (dst) { *dst = new_vl; } So that we won't generate store to nullptr if we pass a nullptr to vleff intrinsics. This behavior is compatible with GCC. As for the difference when compiling with -O3, it is because GCC handles this UB (store to nullptr) in other way. But as you can see, `sw zero,0(zero)` will cause interruption (runtime errors). I don't know if we should make LLVM and GCC with the same behavior to handle stores to null, which is beyond this patch. > ex. > > int foo (int j){ > int *k = nullptr; > *k = 10; > return 100; > } > > compiling with `-O3`, llvm generates empty function but gcc generates > > foo(int): > sw zero,0(zero) > ebreak > > https://godbolt.org/z/46vGrzs49 > > Please correct me if I misunderstand something, thanks. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D126461/new/ https://reviews.llvm.org/D126461 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits