[PATCH] D117450: [LoopInterchange] Support loop interchange with floating point reductions

Congzhe Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 24 11:40:09 PST 2022


congzhe updated this revision to Diff 402606.
congzhe added a reviewer: Meinersbur.
congzhe added a comment.

@Meinersbur Thank you for the comments, I've updated the patch accordingly.

I've made use of `RecurrenceDescriptor::isReductionPHI`, especially `RecurrenceDescriptor::getExactFPMathInst()` to determine whether it is safe to reorer FP instructions. This is similar to what we've done in loop vectorization.

However, it seems that there is a bug in `RecurrenceDescriptor`, as it fails to detect cases where there's two fadd instructions involved in the FP reduction and only one of them has the "fast" flag (please refer to `test5` in `reductions-across-inner-and-outer-loop.ll` below). In this case `RecurrenceDescriptor::getExactFPMathInst()` is supposed to return the fadd instruction that does not have the "fast" flag meaning it is unsafe to reorder them, but it returns NULL meaning it determines it is safe to reorder them.

I've changed `IVDescriptor.cpp` to fix the bug and temporarily included the change in this patch, but I'll post this part of change as another phabricator patch and rebase this patch on top.

> Instead of using isFast(), I now use hasAllowReassoc().

Since we now use helper functions from IVDescriptor, this is less of an issue for now. Nevertheless in `RecurrenceDescriptor::isRecurrenceInstr()` it seems like they only check `I->hasAllowReassoc()`.

> Regarding "unsafe-fp-math" VS "fast":

it does look like "unsafe-fp-math"  is deprecated and it is not dealt with by any mid-end passes, so I removed the handling of "unsafe-fp-math".


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117450/new/

https://reviews.llvm.org/D117450

Files:
  llvm/lib/Analysis/IVDescriptors.cpp
  llvm/lib/Transforms/Scalar/LoopInterchange.cpp
  llvm/test/Transforms/LoopInterchange/lcssa.ll
  llvm/test/Transforms/LoopInterchange/reductions-across-inner-and-outer-loop.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117450.402606.patch
Type: text/x-patch
Size: 14902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220124/3df779a0/attachment.bin>


More information about the llvm-commits mailing list