This is an archive of the discontinued LLVM Phabricator instance.

[ARM][LowOverheadLoops] Add LR def safety check
ClosedPublic

Authored by samparker on Sep 13 2019, 2:02 AM.

Details

Summary

Converting the *LoopStart pseudo instructions into DLS/WLS results in LR being defined. These instructions were inserted on the assumption that LR would already contain the loop counter because a mov is introduced during ISel as the the consumers in the loop can only use LR. That assumption proved wrong! So perform a safety check, finding an appropriate place to insert the DLS/WLS instructions or revert if this isn't possible.

Almost all the tests have changed because liveness tracking is enabled.

Diff Detail

Repository
rL LLVM

Event Timeline

samparker created this revision.Sep 13 2019, 2:02 AM

Will tracking liveness this late be OK? I have a memory of it not being reliable, but that might have been fixed up recently?

And it seems a little odd that the t2DoLoopStart/t2WhileLoopStart wouldn't have any reference to LR in it! But that's what it is. Lets get this problem fixed first.

lib/Target/ARM/ARMLowOverheadLoops.cpp
122 ↗(On Diff #220052)

Can this be something like for(auto MI : make_range(T(Begin), End)) ?

155 ↗(On Diff #220052)

Is this always just a tMOVr? Would it be better to check that specifically?

169 ↗(On Diff #220052)

Is the template type needed, or can it be left implicit?

182 ↗(On Diff #220052)

To > Do this

samparker marked an inline comment as done.Sep 17 2019, 12:58 AM

For the liveness used here, it's just based upon collecting the live ins from the successor blocks and I though that was okay. Thanks for the iterator suggestions, I'll look into them.

lib/Target/ARM/ARMLowOverheadLoops.cpp
155 ↗(On Diff #220052)

sounds good.

samparker updated this revision to Diff 220462.Sep 17 2019, 2:56 AM
  • Removed the template from SearchUse as we only use it once.
  • Updated the searches to iterate over a range.
  • Tried to see if the iterator kind, for SearchDef, could be implicit, but I didn't find a way to have a generic 'iterator' for the machine block - one without its direction defined.
dmgreen accepted this revision.Sep 17 2019, 3:54 AM

LGTM. Thanks.

lib/Target/ARM/ARMLowOverheadLoops.cpp
169 ↗(On Diff #220052)

I meant can it just be: MachineInstr *PredLRDef =SearchForDef(Start, MBB->rend(), ARM::LR), and it picks up the reverse_iterator automatically from the rend type. So SearchForDef is the same template, it's just that the template type is implicit from the args. I'm not sure if this will work or not (or if it's actually better!)

This revision is now accepted and ready to land.Sep 17 2019, 3:54 AM
samparker marked an inline comment as done.Sep 17 2019, 5:00 AM
samparker added inline comments.
lib/Target/ARM/ARMLowOverheadLoops.cpp
169 ↗(On Diff #220052)

Well every day is a school day - I didn't know that was a thing! Will change before committing. Thanks!

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 17 2019, 5:20 AM

@samparker I think your recent commits are causing failures on EXPENSIVE_CHECKS builds, please can you take a look?
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/19705/steps/test-check-all/logs/stdio

Failing Tests (20):
    LLVM :: CodeGen/ARM/2011-12-19-sjlj-clobber.ll
    LLVM :: CodeGen/ARM/constant-island-movwt.mir
    LLVM :: CodeGen/ARM/constant-islands-cfg.mir
    LLVM :: CodeGen/ARM/constant-islands-split-IT.mir
    LLVM :: CodeGen/ARM/fp16-litpool-arm.mir
    LLVM :: CodeGen/ARM/fp16-litpool-thumb.mir
    LLVM :: CodeGen/ARM/jump-table-islands.ll
    LLVM :: CodeGen/ARM/space-directive.ll
    LLVM :: CodeGen/ARM/thumb-big-stack.ll
    LLVM :: CodeGen/ARM/v8m.base-jumptable_alignment.ll
    LLVM :: CodeGen/Thumb/pr42760.ll
    LLVM :: CodeGen/Thumb2/LowOverheadLoops/massive.mir
    LLVM :: CodeGen/Thumb2/LowOverheadLoops/multiblock-massive.mir
    LLVM :: CodeGen/Thumb2/LowOverheadLoops/revert-non-header.mir
    LLVM :: CodeGen/Thumb2/LowOverheadLoops/size-limit.mir
    LLVM :: CodeGen/Thumb2/LowOverheadLoops/switch.mir
    LLVM :: CodeGen/Thumb2/constant-islands-new-island.ll
    LLVM :: CodeGen/Thumb2/constant-islands.ll
    LLVM :: CodeGen/Thumb2/large-call.ll
    LLVM :: CodeGen/Thumb2/thumb2-tbh.ll

@samparker : right after r372126 there still seems to be a test failure remaining:

; CHECK-NEXT: Machine Natural Loop Construction
              ^
<stdin>:156:2: note: 'next' match was here
 Machine Natural Loop Construction
 ^
<stdin>:154:58: note: previous match ended here
 ARM constant island placement and branch shortening pass
                                                         ^
<stdin>:155:1: note: non-matching line after previous match is here
 MachineDominator Tree Construction
^

--

********************
Testing Time: 96.32s
********************
Failing Tests (1):
    LLVM :: CodeGen/ARM/O3-pipeline.ll

  Expected Passes    : 32993
  Expected Failures  : 147
  Unsupported Tests  : 433
  Unexpected Failures: 1
FAILED: test/CMakeFiles/check-llvm

Hello. Yes, that should all be fixed now. Let us know if anything else is looking off.

Hello. Yes, that should all be fixed now. Let us know if anything else is looking off.

@samparker @dmgreen CodeGen/Thumb2/LowOverheadLoops/massive.mir is still failing on EXPENSIVE_CHECKS builds - please can you take a look?

@RKSimon Sorry! Should now be done in rL372303.

llvm/trunk/test/CodeGen/Thumb2/LowOverheadLoops/revert-after-read.mir