-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[ARM][Thumb2] Allow 2-operand variants of [us]div
#119976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-mc @llvm/pr-subscribers-backend-arm Author: Dmitry Chestnykh (chestnykh) ChangesFixes #119963 Full diff: https://github.com/llvm/llvm-project/pull/119976.diff 3 Files Affected:
diff --git a/llvm/lib/Target/ARM/ARMInstrInfo.td b/llvm/lib/Target/ARM/ARMInstrInfo.td
index 1cb6589184b603..c67177cd5a6fea 100644
--- a/llvm/lib/Target/ARM/ARMInstrInfo.td
+++ b/llvm/lib/Target/ARM/ARMInstrInfo.td
@@ -4765,6 +4765,7 @@ def : ARMV6Pat<(int_arm_smusdx GPRnopc:$Rn, GPRnopc:$Rm),
//===----------------------------------------------------------------------===//
// Division Instructions (ARMv7-A with virtualization extension)
//
+let TwoOperandAliasConstraint = "$Rn = $Rd" in {
def SDIV : ADivA1I<0b001, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), IIC_iDIV,
"sdiv", "\t$Rd, $Rn, $Rm",
[(set GPR:$Rd, (sdiv GPR:$Rn, GPR:$Rm))]>,
@@ -4776,6 +4777,7 @@ def UDIV : ADivA1I<0b011, (outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm), IIC_iDIV,
[(set GPR:$Rd, (udiv GPR:$Rn, GPR:$Rm))]>,
Requires<[IsARM, HasDivideInARM]>,
Sched<[WriteDIV]>;
+}
//===----------------------------------------------------------------------===//
// Misc. Arithmetic Instructions.
diff --git a/llvm/lib/Target/ARM/ARMInstrThumb2.td b/llvm/lib/Target/ARM/ARMInstrThumb2.td
index 9ff056f9c06a16..5f01cfcb53f9cf 100644
--- a/llvm/lib/Target/ARM/ARMInstrThumb2.td
+++ b/llvm/lib/Target/ARM/ARMInstrThumb2.td
@@ -3300,6 +3300,7 @@ def : Thumb2DSPPat<(ARMSmlsldx rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi),
// Division Instructions.
// Signed and unsigned division on v7-M
//
+let TwoOperandAliasConstraint = "$Rn = $Rd" in {
def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
"sdiv", "\t$Rd, $Rn, $Rm",
[(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
@@ -3323,6 +3324,7 @@ def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
let Inst{15-12} = 0b1111;
let Inst{7-4} = 0b1111;
}
+}
//===----------------------------------------------------------------------===//
// Misc. Arithmetic Instructions.
diff --git a/llvm/test/MC/ARM/idiv-2op.s b/llvm/test/MC/ARM/idiv-2op.s
new file mode 100644
index 00000000000000..07fadb8056f07a
--- /dev/null
+++ b/llvm/test/MC/ARM/idiv-2op.s
@@ -0,0 +1,42 @@
+@ RUN: llvm-mc -triple=armv7 -mcpu=cortex-m3 -show-encoding < %s 2>&1 | FileCheck -check-prefix M3-ARM %s
+@ RUN: llvm-mc -triple=thumbv7 -mcpu=cortex-m3 -show-encoding < %s 2>&1 | FileCheck -check-prefix M3-THUMB %s
+
+@ RUN: llvm-mc -triple=thumbv7 -mcpu=cortex-a15 -show-encoding < %s 2>&1 | FileCheck -check-prefix A15-THUMB %s
+@ RUN: llvm-mc -triple=thumbv7 -mcpu=cortex-a15 -show-encoding < %s 2>&1 | FileCheck -check-prefix A15-THUMB %s
+
+@ RUN: llvm-mc -triple=armv7 -mcpu=cortex-a15 -mattr=-hwdiv -show-encoding < %s 2>&1 | FileCheck -check-prefix A15-ARM-NOTHUMBHWDIV %s
+@ RUN: llvm-mc -triple=thumbv7 -mcpu=cortex-a15 -mattr=-hwdiv-arm -show-encoding < %s 2>&1 | FileCheck -check-prefix A15-THUMB-NOARMHWDIV %s
+
+@ RUN: llvm-mc -triple=armv8 -show-encoding < %s 2>&1 | FileCheck -check-prefix ARMV8 %s
+@ RUN: llvm-mc -triple=thumbv8 -show-encoding < %s 2>&1 | FileCheck -check-prefix THUMBV8 %s
+
+@ RUN: llvm-mc -triple=armv8 -mattr=-hwdiv -show-encoding < %s 2>&1 | FileCheck -check-prefix ARMV8-NOTHUMBHWDIV %s
+@ RUN: llvm-mc -triple=thumbv8 -mattr=-hwdiv-arm -show-encoding < %s 2>&1 | FileCheck -check-prefix THUMBV8-NOTHUMBHWDIV %s
+
+ sdiv r1, r2
+ udiv r3, r4
+
+@ M3-ARM: sdiv r1, r1, r2 @ encoding: [0x91,0xfb,0xf2,0xf1]
+@ M3-ARM: udiv r3, r3, r4 @ encoding: [0xb3,0xfb,0xf4,0xf3]
+@ M3-THUMB: sdiv r1, r1, r2 @ encoding: [0x91,0xfb,0xf2,0xf1]
+@ M3-THUMB: udiv r3, r3, r4 @ encoding: [0xb3,0xfb,0xf4,0xf3]
+
+@ A15-ARM: sdiv r1, r1, r2 @ encoding: [0x11,0xf2,0x11,0xe7]
+@ A15-ARM: udiv r3, r3, r4 @ encoding: [0x13,0xf4,0x33,0xe7]
+@ A15-THUMB: sdiv r1, r1, r2 @ encoding: [0x91,0xfb,0xf2,0xf1]
+@ A15-THUMB: udiv r3, r3, r4 @ encoding: [0xb3,0xfb,0xf4,0xf3]
+
+@ A15-ARM-NOTHUMBHWDIV: sdiv r1, r1, r2 @ encoding: [0x11,0xf2,0x11,0xe7]
+@ A15-ARM-NOTHUMBHWDIV: udiv r3, r3, r4 @ encoding: [0x13,0xf4,0x33,0xe7]
+@ A15-THUMB-NOARMHWDIV: sdiv r1, r1, r2 @ encoding: [0x91,0xfb,0xf2,0xf1]
+@ A15-THUMB-NOARMHWDIV: udiv r3, r3, r4 @ encoding: [0xb3,0xfb,0xf4,0xf3]
+
+@ ARMV8: sdiv r1, r1, r2 @ encoding: [0x11,0xf2,0x11,0xe7]
+@ ARMV8: udiv r3, r3, r4 @ encoding: [0x13,0xf4,0x33,0xe7]
+@ THUMBV8: sdiv r1, r1, r2 @ encoding: [0x91,0xfb,0xf2,0xf1]
+@ THUMBV8: udiv r3, r3, r4 @ encoding: [0xb3,0xfb,0xf4,0xf3]
+
+@ ARMV8-NOTHUMBHWDIV: sdiv r1, r1, r2 @ encoding: [0x11,0xf2,0x11,0xe7]
+@ ARMV8-NOTHUMBHWDIV: udiv r3, r3, r4 @ encoding: [0x13,0xf4,0x33,0xe7]
+@ THUMBV8-NOTHUMBHWDIV: sdiv r1, r1, r2 @ encoding: [0x91,0xfb,0xf2,0xf1]
+@ THUMBV8-NOTHUMBHWDIV: udiv r3, r3, r4 @ encoding: [0xb3,0xfb,0xf4,0xf3]
|
Contributor
|
Looks reasonable, but I'm not affiliated with ARM to approve. |
ostannard
approved these changes
Dec 16, 2024
Collaborator
ostannard
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LTGM too, with one minor nit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #119963