This is an archive of the discontinued LLVM Phabricator instance.

[Thumb/Thumb2] Implement restrictions on SP in register list on LDM, STM variants in thumb mode
ClosedPublic

Authored by jyoti.allur on Oct 16 2014, 8:17 AM.

Details

Summary

Implement restrictions on SP in register list to LDM, STM variants in thumb mode as specified by ARM ARM
Referred ARM for v7m

Diff Detail

Event Timeline

jyoti.allur retitled this revision from to Implement restrictions on SP in register list on LDM, LDMIA, LDMFD for ARM v7m .
jyoti.allur updated this object.
jyoti.allur edited the test plan for this revision. (Show Details)
jyoti.allur set the repository for this revision to rL LLVM.
jyoti.allur added a subscriber: Unknown Object (MLST).

Hi Jyoti,

Thanks very much for working on this (especially as it's one on my list to get around to). I think there are a few more cases to cover:

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
6000

This restriction seems to apply to all the Thumb2 instructions in this case, not just t2LDMIA_UPD (but watch out for the fallthrough from ARM above).

It also applies to the non-updating variants (you may have to add extra cases).

6001

The list doesn't start at operand 4 here, does it? It looks like it should be 3 again on my tests.

jyoti.allur added inline comments.Oct 17 2014, 7:14 AM
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
6000

yes, this restriction does apply to all thumb2 instructions in this case, i was planning on adding multiple patches for each set of instructions Section wise as mentioned in the ARM ARM, if that's okay with you?.

6001

in some calls to checkLowRegisterList ( though this is a different function from listContainsReg, logic to read registers from list is same for both) operand 4 is used whenever a writeback expression exists in the instruction, since this case covered *_UPD case, 4 was used, correct me if my understanding is wrong.

Hi Tim,

I have replied inline again. LDMEA and STMEA stack operations are not included, should we consider them?

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
6000

okay, I will include non-updating variants namely ARM::t2LDMIA, ARM::t2LDMDB,ARM::t2STMIA,ARM::t2STMDB

What about thumb versions ARM::tLDMIA, ARM::tLDMDB,ARM::tSTMIA,ARM::tSTMDB
i should include them as well rite?

6001

i will change it to operand number 3 when checking for SP, although i am not sure why 4 is used in checkLowRegisterList in some cases.

t.p.northover added inline comments.Oct 17 2014, 9:50 AM
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
6000

That'd be good. I don't think it's necessary to go through separate patches & review for the lot. It's really just one big issue: "LLVM doesn't know sp is forbidden in thumb ldm/stm instructions"

6001

It depends on the exact instruction. I think STMs tend to start at 4, because they duplicate the address register for codegen purposes (once to be read, once to be written). The way to check is

$ echo 'stmia r3!, {r0, r1}' | bin/llvm-mc -triple thumbv7 -show-inst
        stm	r3!, {r0, r1}           @ <MCInst #2769 tSTMIA_UPD
                                    @  <MCOperand Reg:69>
                                    @  <MCOperand Reg:69>
                                    @  <MCOperand Imm:14>
                                    @  <MCOperand Reg:0>
                                    @  <MCOperand Reg:66>
                                    @  <MCOperand Reg:67>>

You see a duplicated 69 (the r3), a couple of predicate related operands, followed by the real register list starting at operand 4 (for tSTMIA_UPD). Hence line 6054.

Oops...

llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
6001

I'm really sorry, you seem to have been right first time. Quite what test I did yesterday, I don't know. But today's one shows that t2LDMIA_UPD *does* start the list at 4.

jyoti.allur retitled this revision from Implement restrictions on SP in register list on LDM, LDMIA, LDMFD for ARM v7m to [ARM] Implement restrictions on SP in register list on LDM, STM variants in thumb mode.
jyoti.allur updated this object.
jyoti.allur edited the test plan for this revision. (Show Details)
jyoti.allur edited edge metadata.
jyoti.allur set the repository for this revision to rL LLVM.

Applied restriction on SP in register list to LDM, STM variants in thumb mode.

jyoti.allur retitled this revision from [ARM] Implement restrictions on SP in register list on LDM, STM variants in thumb mode to [Thumb/Thumb2] Implement restrictions on SP in register list on LDM, STM variants in thumb mode.Oct 21 2014, 7:38 AM
t.p.northover accepted this revision.Oct 21 2014, 10:39 AM
t.p.northover edited edge metadata.

Hi Jyoti,

Thanks for updating the patch. I think it looks fine now.

Tim.

This revision is now accepted and ready to land.Oct 21 2014, 10:39 AM
jyoti.allur closed this revision.Oct 22 2014, 4:02 AM

Hi Tim,
Thanks for the review. Patch was committed in r220379.