This is an incomplete PoC patch; in -O0 mode, the function calls are lowered with GlobalISel which doesn't use the modified functions in AArch64ISelLowering.cpp. When GlobalISel lowers a call in IRTranslator::translateCall in lib/CodeGen/GlobalISel/IRTranslator.cpp, it doesn't have target specific knowledge where it could check for this AArch64 specific feature flag.
Currently this is implemented as target feature flag (used via clang as -Xclang -target-feature -Xclang +protect-x18). This is not ideal though, because it's hard to check for this feature flag in e.g. a configure script; on clang versions that don't have the flag, test compiling with this flag does work but emits a warning (which -Werror doesn't make into an error either).