[aot] Only use an AOT shortcut in the trampoline code if its safe to do so. Fixes #15345.