Right now, when clang targets PowerPC with optimizations, clang defaults to -fomit-frame-pointer for Linux and NetBSD, but not for other targets. The attached patch (for llvm-project.git master) changes the default to -fomit-frame-pointer for all PowerPC targets.
I want this because I am targeting 32-bit PowerPC OpenBSD, where gcc already uses -fomit-frame-pointer by default. All targets except Darwin have a similar System V ELF ABI, so if -fomit-frame-pointer works for Linux and NetBSD, it would probably work for FreeBSD and OpenBSD. (It might work for Darwin, but "Darwin is no longer supported for PowerPC" in llvm's PPCTargetMachine.) The frame pointer r31, when it exists, is almost always an extra copy of the stack pointer r1.
Consider this code: void nothing(void) {}
clang -target powerpc-openbsd -O3 -S nothing.c now emits
With -fomit-frame-pointer or with the patch, clang emits only
blr
Beware that -fno-omit-frame-pointer doesn't work; this patch doesn't fix that. In the near future, I will backport the patch to clang 7 and compile more code.
Extended Description
Right now, when clang targets PowerPC with optimizations, clang defaults to -fomit-frame-pointer for Linux and NetBSD, but not for other targets. The attached patch (for llvm-project.git master) changes the default to -fomit-frame-pointer for all PowerPC targets.
I want this because I am targeting 32-bit PowerPC OpenBSD, where gcc already uses -fomit-frame-pointer by default. All targets except Darwin have a similar System V ELF ABI, so if -fomit-frame-pointer works for Linux and NetBSD, it would probably work for FreeBSD and OpenBSD. (It might work for Darwin, but "Darwin is no longer supported for PowerPC" in llvm's PPCTargetMachine.) The frame pointer r31, when it exists, is almost always an extra copy of the stack pointer r1.
Consider this code: void nothing(void) {}
clang -target powerpc-openbsd -O3 -S nothing.c
now emitsWith -fomit-frame-pointer or with the patch, clang emits only
Beware that -fno-omit-frame-pointer doesn't work; this patch doesn't fix that. In the near future, I will backport the patch to clang 7 and compile more code.