Last active
May 30, 2017 01:46
-
-
Save michaeljclark/58fb3be4d6da7964d5683ec5e4fc7ed0 to your computer and use it in GitHub Desktop.
strict operands for riscv-gcc - emit addi when operand is not a register
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
diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c | |
index 73312712d33..cc797b95a3f 100644 | |
--- a/gcc/config/riscv/riscv.c | |
+++ b/gcc/config/riscv/riscv.c | |
@@ -2786,7 +2786,8 @@ riscv_memmodel_needs_release_fence (enum memmodel model) | |
'C' Print the integer branch condition for comparison OP. | |
'A' Print the atomic operation suffix for memory model OP. | |
'F' Print a FENCE if the memory model requires a release. | |
- 'z' Print x0 if OP is zero, otherwise print OP normally. */ | |
+ 'z' Print x0 if OP is zero, otherwise print OP normally. | |
+ 'i' Print i if the operand is not a register. */ | |
static void | |
riscv_print_operand (FILE *file, rtx op, int letter) | |
@@ -2821,6 +2822,11 @@ riscv_print_operand (FILE *file, rtx op, int letter) | |
fputs ("fence iorw,ow; ", file); | |
break; | |
+ case 'i': | |
+ if (code != REG) | |
+ fputs ("i", file); | |
+ break; | |
+ | |
default: | |
switch (code) | |
{ | |
diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md | |
index 1f79fab54c9..d1cfba561c0 100644 | |
--- a/gcc/config/riscv/riscv.md | |
+++ b/gcc/config/riscv/riscv.md | |
@@ -414,7 +414,7 @@ | |
(plus:SI (match_operand:SI 1 "register_operand" " r,r") | |
(match_operand:SI 2 "arith_operand" " r,I")))] | |
"" | |
- { return TARGET_64BIT ? "addw\t%0,%1,%2" : "add\t%0,%1,%2"; } | |
+ { return TARGET_64BIT ? "add%i2w\t%0,%1,%2" : "add%i2\t%0,%1,%2"; } | |
[(set_attr "type" "arith") | |
(set_attr "mode" "SI")]) | |
@@ -423,7 +423,7 @@ | |
(plus:DI (match_operand:DI 1 "register_operand" " r,r") | |
(match_operand:DI 2 "arith_operand" " r,I")))] | |
"TARGET_64BIT" | |
- "add\t%0,%1,%2" | |
+ "add%i2\t%0,%1,%2" | |
[(set_attr "type" "arith") | |
(set_attr "mode" "DI")]) | |
@@ -433,7 +433,7 @@ | |
(plus:SI (match_operand:SI 1 "register_operand" " r,r") | |
(match_operand:SI 2 "arith_operand" " r,I"))))] | |
"TARGET_64BIT" | |
- "addw\t%0,%1,%2" | |
+ "add%i2w\t%0,%1,%2" | |
[(set_attr "type" "arith") | |
(set_attr "mode" "SI")]) | |
@@ -444,7 +444,7 @@ | |
(match_operand:DI 2 "arith_operand" " r,I")) | |
0)))] | |
"TARGET_64BIT" | |
- "addw\t%0,%1,%2" | |
+ "add%i2w\t%0,%1,%2" | |
[(set_attr "type" "arith") | |
(set_attr "mode" "SI")]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment