[PATCH] D135451: [TTI] New PPC target hook enableUncondDivisionSpeculation

Alex Gatea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 08:39:29 PDT 2022


alexgatea created this revision.
alexgatea added reviewers: nemanjai, bmahjour.
alexgatea added a project: LLVM.
Herald added subscribers: shchenz, asbirlea, kbarton, hiraditya.
Herald added a project: All.
alexgatea requested review of this revision.
Herald added a subscriber: llvm-commits.

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;




Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135451

Files:
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/Analysis/ValueTracking.h
  llvm/include/llvm/Transforms/Utils/LoopUtils.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h
  llvm/lib/Transforms/Scalar/LICM.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135451.466084.patch
Type: text/x-patch
Size: 13855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221007/12330afb/attachment.bin>


More information about the llvm-commits mailing list