Created PPC-specific TTI hook for enabling unconditional speculative execution of division operations in llvm::isSafeToSpeculativelyExecute(). Integer division by 0 does not cause an exception on PPC, so it should be safe to speculate divide operations. This allows the compiler to optimize more aggressively, which benefits other passes.
For example, consider the following code optimized with clang -O3
void foo (int m); int fcn (int x, int y){ int n = 0; for(int i = 0; i < 1000; i++){ foo(0); n += x/y; } return n; }
With the speculative execution off, the final assembly file effectively does
int n = 0; int tmp = x/y; for(int i = 0; i < 1000; i++){ foo(0); n += tmp; } return n;
However, with the speculative execution on, LICM hoists the division early in the pipeline which allows IndVarSimplifyPass to optimize
n += tmp in the loop to a multiplication at the end:
for(int i = 0; i < 1000; i++) foo(0); return (x/y) * 1000;