This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Correct POP reglist handling
ClosedPublic

Authored by jyoti.allur on Dec 31 2014, 8:22 AM.

Details

Reviewers
compnerd
Summary

ARM for v7-m states
POP
SP cannot be in the list

and GCC obliges with an error message for v7m
"Error: invalid register list to push/pop instruction -- `pop {sp}'"

Diff Detail

Event Timeline

jyoti.allur retitled this revision from to [ARM] Correct POP reglist handling.
jyoti.allur updated this object.
jyoti.allur edited the test plan for this revision. (Show Details)
jyoti.allur added a reviewer: compnerd.
jyoti.allur set the repository for this revision to rL LLVM.
compnerd requested changes to this revision.Dec 31 2014, 10:27 AM
compnerd edited edge metadata.

This is incorrect. pop {sp} is permitted on armv7-a and armv7-r. You are correct, I did not correctly account for armv7-m. This would result in incorrect behavior on the A/R targets.

This revision now requires changes to proceed.Dec 31 2014, 10:27 AM

Hi Compnerd,

Some tests with GNU assembler lead me to think pop {sp} is not permitted in v7 a/r targets as well in thumb mode though.

GNU assembler results :-

cat ldmstm.s
pop {r4, sp}

POP(Thumb) mode v7 a/r

arm-linux-gnueabi-as -march=armv7r -mthumb ldmstm.s
ldmstm.s: Assembler messages:
ldmstm.s:12: Error: invalid register list to push/pop instruction -- `pop {r4,sp}'

arm-linux-gnueabi-as -march=armv7a -mthumb ldmstm.s
ldmstm.s: Assembler messages:
ldmstm.s:12: Error: invalid register list to push/pop instruction -- `pop {r4,sp}'

Without this patch, SP was allowed in POP(Thumb mode) for v7 A/R targets, resulting in
pop.w {r4, sp}

This patch does not affect POP(ARM mode) for v7 A/R targets as it is handled in getARMLoadDeprecationInfo.
Let me know if the correction should still be done for v7m alone? i'll modify accordingly.

jyoti.allur edited edge metadata.Jan 5 2015, 3:13 AM
jyoti.allur added a subscriber: Unknown Object (MLST).

The current revision of the ARM ARM seems to indicate that pop {sp} is permitted. I think that this may be a bug in GAS (its tricky since ldm {sp} is not permitted, but pop can be relaxed to a ldm). I think for now, being more conservative and just changing the IsPop to IsARPop and passing that information along might be the better solution.

jyoti.allur updated this revision to Diff 17827.Jan 6 2015, 2:30 AM
jyoti.allur edited edge metadata.

Alright, modified accordingly.
sub arch and arch profile information is unavailable in AsmParser, i have made use of the feature bits for MClass to know whether POP is for AR targets or not. Consequently, I had no choice but to to replicate the testcases for v7m.
A and R are defined by same manual, so i assume no need to test for R seperately.
Thanks.

Hi Saleem,
Could you please review this, shouldn't take much of you time as changes are minimal.
Thanks!

jroelofs added inline comments.
../llvm/test/MC/ARM/thumb-load-store-multiple.s
4

Instead of duplicating all of the shared cases below, how about:

@ RUN: not llvm-mc -triple thumbv7a-eabi -filetype asm -o - %s 2>&1 \
@ RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-V7A %s
@ RUN: not llvm-mc -triple thumbv7m-eabi -filetype asm -o - %s 2>&1 \
@ RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-V7M %s

Then only split out the cases that are different. I think that will significantly reduce the diff in this file.

I agree with jroelofs' suggestion about the test changes. I think that would make it easier to maintain as well.

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

The variable here is unnecessary. I would just inline the call to !isMClass() not the call to validateLDMRegList.

jyoti.allur edited edge metadata.
jyoti.allur removed rL LLVM as the repository for this revision.

Ah. why din't i think about it. Thanks Jonathan and Saleem.
Updated the diff.

compnerd accepted this revision.Jan 12 2015, 6:55 PM
compnerd edited edge metadata.

Thanks for addressing all the review comments.

../llvm/test/MC/ARM/thumb-load-store-multiple.s
13

oops.

34

Ugh. Thanks for fixing this.

This revision is now accepted and ready to land.Jan 12 2015, 6:55 PM
jyoti.allur closed this revision.Jan 14 2015, 2:54 AM

Thanks for reviewing.
Closed by commit rL225972 (authored @jyoti.allur )