[llvm-commits] [PATCH 09/11] (patch) Mips specific inline asm: constraint 'P'
Jack Carter
jcarter at mips.com
Thu Apr 12 13:51:46 PDT 2012
A constant in te range of 1 to 65535 inclusive.
Example:
int i_input = 7; int i_result = 0;
// Good: i_val falls in the correct range
int i_val = 3;
__asm__ __volatile__(
"addi %0,%1,%2" : "=r" (i_result) : "r" (i_input), "N" (i_val));
// Bad: llc should produce an error
int i_val = -3;
__asm__ __volatile__(
"addi %0,%1,%2" : "=r" (i_result) : "r" (i_input), "N" (i_val));
---
lib/Target/Mips/MipsISelLowering.cpp | 11 +++++++++++
test/CodeGen/Mips/inlineasm-cnstrnt-bad-P.ll | 13 +++++++++++++
test/CodeGen/Mips/inlineasm_constraint.ll | 6 ++++++
3 files changed, 30 insertions(+), 0 deletions(-)
create mode 100644 test/CodeGen/Mips/inlineasm-cnstrnt-bad-P.ll
-------------- next part --------------
diff --git a/lib/Target/Mips/MipsISelLowering.cpp b/lib/Target/Mips/MipsISelLowering.cpp
index 4d1d7ad..bf0779e 100644
--- a/lib/Target/Mips/MipsISelLowering.cpp
+++ b/lib/Target/Mips/MipsISelLowering.cpp
@@ -2932,6 +2932,7 @@ MipsTargetLowering::getSingleConstraintMatchWeight(
case 'L': // signed 32 bit immediate where lower 16 bits are 0
case 'N': // immediate in the range of -65535 to -1 (inclusive)
case 'O': // signed 15 bit immediate (+- 16383)
+ case 'P': // immediate in the range of 65535 to 1 (inclusive)
if (isa<ConstantInt>(CallOperandVal))
weight = CW_Constant;
break;
@@ -3045,6 +3046,16 @@ void MipsTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
}
}
return;
+ case 'P': // immediate in the range of 1 to 65535 (inclusive)
+ if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
+ EVT Type = Op.getValueType();
+ int64_t Val = C->getSExtValue();
+ if ((Val <= 65535) && (Val >= 1)) {
+ Result = DAG.getTargetConstant(Val, Type);
+ break;
+ }
+ }
+ return;
}
if (Result.getNode()) {
diff --git a/test/CodeGen/Mips/inlineasm-cnstrnt-bad-P.ll b/test/CodeGen/Mips/inlineasm-cnstrnt-bad-P.ll
new file mode 100644
index 0000000..ea7aed9
--- /dev/null
+++ b/test/CodeGen/Mips/inlineasm-cnstrnt-bad-P.ll
@@ -0,0 +1,13 @@
+;XFAIL:
+;
+; This is a negative test. The constant value given for the constraint (P).
+; A constant in the range of 1 to 655535 inclusive.
+; Our example uses the positive value 655536.
+;
+; RUN: not llc -march=mipsel < %s
+
+define i32 @main() nounwind {
+entry:
+ tail call i32 asm sideeffect "addi $0,$1,$2", "=r,r,P"(i32 undef, i32 655536) nounwind
+ ret i32 0
+}
diff --git a/test/CodeGen/Mips/inlineasm_constraint.ll b/test/CodeGen/Mips/inlineasm_constraint.ll
index cb02dd1..97a5678 100644
--- a/test/CodeGen/Mips/inlineasm_constraint.ll
+++ b/test/CodeGen/Mips/inlineasm_constraint.ll
@@ -45,5 +45,11 @@ entry:
; CHECK: #NO_APP
tail call i32 asm sideeffect "addi $0,$1,$2", "=r,r,O"(i32 7, i16 -3) nounwind
+; Now P with 65535
+; CHECK: #APP
+; CHECK: addi ${{[0-9]+}},${{[0-9]+}},65535
+; CHECK: #NO_APP
+ tail call i32 asm sideeffect "addi $0,$1,$2", "=r,r,P"(i32 7, i32 65535) nounwind
+
ret i32 0
}
More information about the llvm-commits
mailing list