[llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
Hi all,

I’m trying to insert some add/sub and push/pop instructions in a MachineFunction pass for ARMv7-M. However, I encountered something weird.
For an add, when I use

        BuildMI(….., TII->get(ARM::tADDi8), reg).addReg(reg).addReg(reg).addImm(imm).

if reg is R0 - R7, everything is fine: I would get something like

        adds r1, 4

But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register in the assembly code. For example, when I pass R8 to it, I would get

        adds r0, 4

rather than

        adds r8, 4.

Similar problems happen to push and pop instructions. I can create a push/pop if the register list only contains registers R0 - R7, but
for registers whose number are greater than R7, the generated asm code doesn’t have it. For example,

        BuildMI(……, TII->get(ARM::tPUSH), R8)…..

would give me

        push {}

Is this a bug in the LLVM ARM code generator? Or is there a reason why we cannot use big-number registers for add/sub and push/pop?

Thanks,
- Jie
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
I don't know much about ARM. But it looks like tADDi8 is a Thumb instruction and it can only use R0-R7.

tPUSH probably as a similar issue. But it's also a store instruction and doesn't produce a register output. So you should use the form of BuildMI that doesn't take a register as its last argument.

~Craig


On Sun, Apr 14, 2019 at 11:17 AM Jie Zhou via llvm-dev <[hidden email]> wrote:
Hi all,

I’m trying to insert some add/sub and push/pop instructions in a MachineFunction pass for ARMv7-M. However, I encountered something weird.
For an add, when I use

        BuildMI(….., TII->get(ARM::tADDi8), reg).addReg(reg).addReg(reg).addImm(imm).

if reg is R0 - R7, everything is fine: I would get something like

        adds r1, 4

But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register in the assembly code. For example, when I pass R8 to it, I would get

        adds r0, 4

rather than

        adds r8, 4.

Similar problems happen to push and pop instructions. I can create a push/pop if the register list only contains registers R0 - R7, but
for registers whose number are greater than R7, the generated asm code doesn’t have it. For example,

        BuildMI(……, TII->get(ARM::tPUSH), R8)…..

would give me

        push {}

Is this a bug in the LLVM ARM code generator? Or is there a reason why we cannot use big-number registers for add/sub and push/pop?

Thanks,
- Jie
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
Sorry for not being specific enough. ARMv7-M includes Thumb and Thumb2. 
It has 12 regular registers (R0 - R12), and R8 - R12 are used. 
I can generate mov instruction that from/ R8-R12 to/from R0-R6. 
R9 - R12 have their conventional usage, but I don’t if this is the reason we cannot 
use them arbitrarily. The fact that we can use it to generate mov instructions but
not add/sub and push/pop confuses me.

- Jie

On Apr 14, 2019, at 14:55, Craig Topper <[hidden email]> wrote:

I don't know much about ARM. But it looks like tADDi8 is a Thumb instruction and it can only use R0-R7.

tPUSH probably as a similar issue. But it's also a store instruction and doesn't produce a register output. So you should use the form of BuildMI that doesn't take a register as its last argument.

~Craig


On Sun, Apr 14, 2019 at 11:17 AM Jie Zhou via llvm-dev <[hidden email]> wrote:
Hi all,

I’m trying to insert some add/sub and push/pop instructions in a MachineFunction pass for ARMv7-M. However, I encountered something weird.
For an add, when I use

        BuildMI(….., TII->get(ARM::tADDi8), reg).addReg(reg).addReg(reg).addImm(imm).

if reg is R0 - R7, everything is fine: I would get something like

        adds r1, 4

But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register in the assembly code. For example, when I pass R8 to it, I would get

        adds r0, 4

rather than

        adds r8, 4.

Similar problems happen to push and pop instructions. I can create a push/pop if the register list only contains registers R0 - R7, but
for registers whose number are greater than R7, the generated asm code doesn’t have it. For example,

        BuildMI(……, TII->get(ARM::tPUSH), R8)…..

would give me

        push {}

Is this a bug in the LLVM ARM code generator? Or is there a reason why we cannot use big-number registers for add/sub and push/pop?

Thanks,
- Jie
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
I believe there is probably a separate instruction in LLVM for thumb2 add. Probably starting with t2 instead of t.

The definition of tADDi8 looks like this. Where tGPR specifically means R0-R7.

  def tADDi8 :                    // A8.6.4 T2
    T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
                      (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
                      "add", "\t$Rdn, $imm8",
                      [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
                      Sched<[WriteALU]>;

~Craig


On Sun, Apr 14, 2019 at 12:21 PM Jie Zhou <[hidden email]> wrote:
Sorry for not being specific enough. ARMv7-M includes Thumb and Thumb2. 
It has 12 regular registers (R0 - R12), and R8 - R12 are used. 
I can generate mov instruction that from/ R8-R12 to/from R0-R6. 
R9 - R12 have their conventional usage, but I don’t if this is the reason we cannot 
use them arbitrarily. The fact that we can use it to generate mov instructions but
not add/sub and push/pop confuses me.

- Jie

On Apr 14, 2019, at 14:55, Craig Topper <[hidden email]> wrote:

I don't know much about ARM. But it looks like tADDi8 is a Thumb instruction and it can only use R0-R7.

tPUSH probably as a similar issue. But it's also a store instruction and doesn't produce a register output. So you should use the form of BuildMI that doesn't take a register as its last argument.

~Craig


On Sun, Apr 14, 2019 at 11:17 AM Jie Zhou via llvm-dev <[hidden email]> wrote:
Hi all,

I’m trying to insert some add/sub and push/pop instructions in a MachineFunction pass for ARMv7-M. However, I encountered something weird.
For an add, when I use

        BuildMI(….., TII->get(ARM::tADDi8), reg).addReg(reg).addReg(reg).addImm(imm).

if reg is R0 - R7, everything is fine: I would get something like

        adds r1, 4

But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register in the assembly code. For example, when I pass R8 to it, I would get

        adds r0, 4

rather than

        adds r8, 4.

Similar problems happen to push and pop instructions. I can create a push/pop if the register list only contains registers R0 - R7, but
for registers whose number are greater than R7, the generated asm code doesn’t have it. For example,

        BuildMI(……, TII->get(ARM::tPUSH), R8)…..

would give me

        push {}

Is this a bug in the LLVM ARM code generator? Or is there a reason why we cannot use big-number registers for add/sub and push/pop?

Thanks,
- Jie
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
Hi Craig,

Thanks for the information. Can you point to the source that specifies tGPR to be R0 - R7?
I tried to search in ARMInstrThumb.td but couldn’t find it.

Thanks,
- Jie

On Apr 14, 2019, at 15:28, Craig Topper <[hidden email]> wrote:

I believe there is probably a separate instruction in LLVM for thumb2 add. Probably starting with t2 instead of t.

The definition of tADDi8 looks like this. Where tGPR specifically means R0-R7.

  def tADDi8 :                    // A8.6.4 T2
    T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
                      (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
                      "add", "\t$Rdn, $imm8",
                      [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
                      Sched<[WriteALU]>;

~Craig


On Sun, Apr 14, 2019 at 12:21 PM Jie Zhou <[hidden email]> wrote:
Sorry for not being specific enough. ARMv7-M includes Thumb and Thumb2. 
It has 12 regular registers (R0 - R12), and R8 - R12 are used. 
I can generate mov instruction that from/ R8-R12 to/from R0-R6. 
R9 - R12 have their conventional usage, but I don’t if this is the reason we cannot 
use them arbitrarily. The fact that we can use it to generate mov instructions but
not add/sub and push/pop confuses me.

- Jie

On Apr 14, 2019, at 14:55, Craig Topper <[hidden email]> wrote:

I don't know much about ARM. But it looks like tADDi8 is a Thumb instruction and it can only use R0-R7.

tPUSH probably as a similar issue. But it's also a store instruction and doesn't produce a register output. So you should use the form of BuildMI that doesn't take a register as its last argument.

~Craig


On Sun, Apr 14, 2019 at 11:17 AM Jie Zhou via llvm-dev <[hidden email]> wrote:
Hi all,

I’m trying to insert some add/sub and push/pop instructions in a MachineFunction pass for ARMv7-M. However, I encountered something weird.
For an add, when I use

        BuildMI(….., TII->get(ARM::tADDi8), reg).addReg(reg).addReg(reg).addImm(imm).

if reg is R0 - R7, everything is fine: I would get something like

        adds r1, 4

But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register in the assembly code. For example, when I pass R8 to it, I would get

        adds r0, 4

rather than

        adds r8, 4.

Similar problems happen to push and pop instructions. I can create a push/pop if the register list only contains registers R0 - R7, but
for registers whose number are greater than R7, the generated asm code doesn’t have it. For example,

        BuildMI(……, TII->get(ARM::tPUSH), R8)…..

would give me

        push {}

Is this a bug in the LLVM ARM code generator? Or is there a reason why we cannot use big-number registers for add/sub and push/pop?

Thanks,
- Jie
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
It's in ARMRegisterInfo.td

// Thumb registers are R0-R7 normally. Some instructions can still use
// the general GPR register class above (MOV, e.g.)
def tGPR : RegisterClass<"ARM", [i32], 32, (trunc GPR, 8)> {
  let DiagnosticString = "operand must be a register in range [r0, r7]";
}

~Craig


On Sun, Apr 14, 2019 at 12:38 PM Jie Zhou <[hidden email]> wrote:
Hi Craig,

Thanks for the information. Can you point to the source that specifies tGPR to be R0 - R7?
I tried to search in ARMInstrThumb.td but couldn’t find it.

Thanks,
- Jie

On Apr 14, 2019, at 15:28, Craig Topper <[hidden email]> wrote:

I believe there is probably a separate instruction in LLVM for thumb2 add. Probably starting with t2 instead of t.

The definition of tADDi8 looks like this. Where tGPR specifically means R0-R7.

  def tADDi8 :                    // A8.6.4 T2
    T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
                      (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
                      "add", "\t$Rdn, $imm8",
                      [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
                      Sched<[WriteALU]>;

~Craig


On Sun, Apr 14, 2019 at 12:21 PM Jie Zhou <[hidden email]> wrote:
Sorry for not being specific enough. ARMv7-M includes Thumb and Thumb2. 
It has 12 regular registers (R0 - R12), and R8 - R12 are used. 
I can generate mov instruction that from/ R8-R12 to/from R0-R6. 
R9 - R12 have their conventional usage, but I don’t if this is the reason we cannot 
use them arbitrarily. The fact that we can use it to generate mov instructions but
not add/sub and push/pop confuses me.

- Jie

On Apr 14, 2019, at 14:55, Craig Topper <[hidden email]> wrote:

I don't know much about ARM. But it looks like tADDi8 is a Thumb instruction and it can only use R0-R7.

tPUSH probably as a similar issue. But it's also a store instruction and doesn't produce a register output. So you should use the form of BuildMI that doesn't take a register as its last argument.

~Craig


On Sun, Apr 14, 2019 at 11:17 AM Jie Zhou via llvm-dev <[hidden email]> wrote:
Hi all,

I’m trying to insert some add/sub and push/pop instructions in a MachineFunction pass for ARMv7-M. However, I encountered something weird.
For an add, when I use

        BuildMI(….., TII->get(ARM::tADDi8), reg).addReg(reg).addReg(reg).addImm(imm).

if reg is R0 - R7, everything is fine: I would get something like

        adds r1, 4

But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register in the assembly code. For example, when I pass R8 to it, I would get

        adds r0, 4

rather than

        adds r8, 4.

Similar problems happen to push and pop instructions. I can create a push/pop if the register list only contains registers R0 - R7, but
for registers whose number are greater than R7, the generated asm code doesn’t have it. For example,

        BuildMI(……, TII->get(ARM::tPUSH), R8)…..

would give me

        push {}

Is this a bug in the LLVM ARM code generator? Or is there a reason why we cannot use big-number registers for add/sub and push/pop?

Thanks,
- Jie
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
Hi Craig,

Thanks very much. I rechecked the ARMv7-M manual and found that the encoding of tADDi8 
(entry A7.7.3, Encoding T2; ARM DDI 0403E.b) only has 3 bits for the register, 
which explains why only R0 - R7 are allowed.

- Jie

On Apr 14, 2019, at 15:39, Craig Topper <[hidden email]> wrote:

It's in ARMRegisterInfo.td

// Thumb registers are R0-R7 normally. Some instructions can still use
// the general GPR register class above (MOV, e.g.)
def tGPR : RegisterClass<"ARM", [i32], 32, (trunc GPR, 8)> {
  let DiagnosticString = "operand must be a register in range [r0, r7]";
}

~Craig


On Sun, Apr 14, 2019 at 12:38 PM Jie Zhou <[hidden email]> wrote:
Hi Craig,

Thanks for the information. Can you point to the source that specifies tGPR to be R0 - R7?
I tried to search in ARMInstrThumb.td but couldn’t find it.

Thanks,
- Jie

On Apr 14, 2019, at 15:28, Craig Topper <[hidden email]> wrote:

I believe there is probably a separate instruction in LLVM for thumb2 add. Probably starting with t2 instead of t.

The definition of tADDi8 looks like this. Where tGPR specifically means R0-R7.

  def tADDi8 :                    // A8.6.4 T2
    T1sItGenEncodeImm<{1,1,0,?,?}, (outs tGPR:$Rdn),
                      (ins tGPR:$Rn, imm0_255:$imm8), IIC_iALUi,
                      "add", "\t$Rdn, $imm8",
                      [(set tGPR:$Rdn, (add tGPR:$Rn, imm8_255:$imm8))]>,
                      Sched<[WriteALU]>;

~Craig


On Sun, Apr 14, 2019 at 12:21 PM Jie Zhou <[hidden email]> wrote:
Sorry for not being specific enough. ARMv7-M includes Thumb and Thumb2. 
It has 12 regular registers (R0 - R12), and R8 - R12 are used. 
I can generate mov instruction that from/ R8-R12 to/from R0-R6. 
R9 - R12 have their conventional usage, but I don’t if this is the reason we cannot 
use them arbitrarily. The fact that we can use it to generate mov instructions but
not add/sub and push/pop confuses me.

- Jie

On Apr 14, 2019, at 14:55, Craig Topper <[hidden email]> wrote:

I don't know much about ARM. But it looks like tADDi8 is a Thumb instruction and it can only use R0-R7.

tPUSH probably as a similar issue. But it's also a store instruction and doesn't produce a register output. So you should use the form of BuildMI that doesn't take a register as its last argument.

~Craig


On Sun, Apr 14, 2019 at 11:17 AM Jie Zhou via llvm-dev <[hidden email]> wrote:
Hi all,

I’m trying to insert some add/sub and push/pop instructions in a MachineFunction pass for ARMv7-M. However, I encountered something weird.
For an add, when I use

        BuildMI(….., TII->get(ARM::tADDi8), reg).addReg(reg).addReg(reg).addImm(imm).

if reg is R0 - R7, everything is fine: I would get something like

        adds r1, 4

But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register in the assembly code. For example, when I pass R8 to it, I would get

        adds r0, 4

rather than

        adds r8, 4.

Similar problems happen to push and pop instructions. I can create a push/pop if the register list only contains registers R0 - R7, but
for registers whose number are greater than R7, the generated asm code doesn’t have it. For example,

        BuildMI(……, TII->get(ARM::tPUSH), R8)…..

would give me

        push {}

Is this a bug in the LLVM ARM code generator? Or is there a reason why we cannot use big-number registers for add/sub and push/pop?

Thanks,
- Jie
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev




_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] [EXT] [A bug?] Failed to use BuildMI to add R7 - R12 registers for tADDi8 and tPUSH of ARM

Chris Lattner via llvm-dev
In reply to this post by Chris Lattner via llvm-dev
tADDi8 and tPUSH specifically refer to 16-bit instructions.  Most 16-bit Thumb instructions are only allowed to refer to low registers.  The corresponding 32-bit instructions are t2ADDri and t2STMDB_UPD.  For more details on ARMv7-M instruction encodings, see the reference manual at https://developer.arm.com/docs/ddi0403/latest .

You're getting weird behavior because the instruction encoder assumes the code doesn't contain any impossible instructions.

-Eli


> -----Original Message-----
> From: llvm-dev <[hidden email]> On Behalf Of Jie Zhou via
> llvm-dev
> Sent: Sunday, April 14, 2019 11:18 AM
> To: llvm-dev <[hidden email]>
> Subject: [EXT] [llvm-dev] [A bug?] Failed to use BuildMI to add R7 - R12 registers
> for tADDi8 and tPUSH of ARM
>
> Hi all,
>
> I’m trying to insert some add/sub and push/pop instructions in a
> MachineFunction pass for ARMv7-M. However, I encountered something weird.
> For an add, when I use
>
> BuildMI(….., TII->get(ARM::tADDi8),
> reg).addReg(reg).addReg(reg).addImm(imm).
>
> if reg is R0 - R7, everything is fine: I would get something like
>
> adds r1, 4
>
> But if I use R8 - R12 as the reg in the BuildMI, I wouldn’t get the correct register
> in the assembly code. For example, when I pass R8 to it, I would get
>
> adds r0, 4
>
> rather than
>
> adds r8, 4.
>
> Similar problems happen to push and pop instructions. I can create a push/pop if
> the register list only contains registers R0 - R7, but
> for registers whose number are greater than R7, the generated asm code
> doesn’t have it. For example,
>
> BuildMI(……, TII->get(ARM::tPUSH), R8)…..
>
> would give me
>
> push {}
>
> Is this a bug in the LLVM ARM code generator? Or is there a reason why we
> cannot use big-number registers for add/sub and push/pop?
>
> Thanks,
> - Jie
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
LLVM Developers mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev