LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1424 - infinite recursion in scavengeregister
Summary: infinite recursion in scavengeregister
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: 2.0
Hardware: All All
: P normal
Assignee: Evan Cheng
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-16 01:30 PDT by Chris Lattner
Modified: 2010-02-22 12:46 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
bugpoint-reduced-simplified.bc (4.38 KB, application/octet-stream)
2007-05-30 17:58 PDT, Lauro Venancio
Details
RegScavenger.patch (2.15 KB, patch)
2007-05-31 11:46 PDT, Lauro Venancio
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2007-05-16 01:30:56 PDT
Get the example from PR1423 (the optimized bc file), run this command:
llc attachment.cgi -o t.s -time-passes -f -fast

You get an infinite recursion:
#6132 0x0020e575 in llvm::RegScavenger::scavengeRegister ()
#6133 0x000356f5 in llvm::ARMRegisterInfo::eliminateFrameIndex ()
#6134 0x0020e575 in llvm::RegScavenger::scavengeRegister ()
#6135 0x000356f5 in llvm::ARMRegisterInfo::eliminateFrameIndex ()
#6136 0x0020e575 in llvm::RegScavenger::scavengeRegister ()
#6137 0x000356f5 in llvm::ARMRegisterInfo::eliminateFrameIndex ()

This seems to depend on -fast.

-Chris
Comment 1 Evan Cheng 2007-05-17 19:12:45 PDT
Does -fast disable coalescing? There might be an issue there if "dead" operands are not propagated.
Comment 2 Chris Lattner 2007-05-17 19:13:43 PDT
yeah, could be.
Comment 3 Lauro Venancio 2007-05-30 17:58:37 PDT
Created attachment 968 [details]
bugpoint-reduced-simplified.bc

This bug can be reproduced without "-fast" using this testcase.
Comment 4 Lauro Venancio 2007-05-30 18:05:06 PDT
This bug occurs when the store in ScavengingFrameIndex has an offset greater
than 2^12 (max ldr/str offset). On this case, the eliminateFrameIndex needs
RegScavenger to emit the store generated by RegScavenger (infinite loop).
Comment 5 Lauro Venancio 2007-05-31 11:46:33 PDT
Created attachment 982 [details]
RegScavenger.patch

This patch makes easier to find this bug.

The RegScavenger mustn't be used to eliminate the ScavengingFrameIndex.
So, we shouldn't pass it to the eliminateFrameIndex function.
Comment 6 Lauro Venancio 2007-05-31 12:17:25 PDT
To solve, I think the ScavengingFrameIndex offset never should be greater than
2^12. For this, we should resort the stack:

When using sp:

---------------------
| callee saved reg  |
---------------------
| static alloca     |
---------------------
| spills            |
---------------------

when using fp:

---------------------
| callee saved reg  |
---------------------
| spills            |
---------------------
| static alloca     |
---------------------
| dynamic alloca    |
---------------------

This solves the bug for the most cases. The bug would persist only for very rare
cases (functions with more than ~1024 spills).
Comment 7 Lauro Venancio 2007-05-31 13:43:13 PDT
Fixed.
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070528/050110.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070528/050111.html

The proposed idea was not implemented because the PrologEpilogInserter already
has code to define the ScavengingFrameIndex offset. This bug was caused by a bug
in this code.
Comment 8 Evan Cheng 2007-05-31 16:28:58 PDT
This is the wrong fix. It's sweeping the bug under the rug.

Even if disabling the use of RS when FP is used is correct (when I am not convinced of), that's up to the 
target to not instantiate RS when it detects that. PEI shouldn't do this check. Please revert the patch.

I've not have a chance to look into this. Please explain, in this case, why is ScavengingFrameIndex not 
within the displacement limit? If there is a bug in the ARMRegisterInfo.cpp code that causes the 
miscalculation, then please fix it.

If we ever run into situation where it's not possible to reserve a legal frame index, then we need a 
proper solution. Can we detect that before register allocation? If so, we need to detect that and reserve 
R12 and make sure RS isn't instantiated.
Comment 9 Lauro Venancio 2007-05-31 17:31:43 PDT
I'm not disabling the use of RS when FP is used. About 30 lines before my
change, there is this code: 

if (RS && RegInfo->hasFP(Fn)) {
    int SFI = RS->getScavengingFrameIndex();
    if (SFI >= 0) {
...

The bug was: the PrologEpilogInserter has two chunks of code to define the
ScavengingFrameIndex offset (one for when fp is used and other for when sp is
used). The sp chunk of code was overwriting the calculation made by fp chunk of
code.
Comment 10 Evan Cheng 2007-05-31 17:46:06 PDT
Now I understand it! :-)