[38/61] MIPSR6: Mark R6 unaligned access

Message ID 20250131171232.1018281-40-aleksandar.rakic@htecgroup.com
State New
Headers
Series Improve Mips target |

Commit Message

Aleksandar Rakic Jan. 31, 2025, 5:13 p.m. UTC
  From: Matthew Fortune <matthew.fortune@imgtec.com>

gcc/
	* config/mips/mips.cc (mips_output_move): Mark unaligned
	load and store with a comment.

Cherry-picked 42be7aa50f3b04a88768e08c000cfe7923f22b0f
from https://github.com/MIPS/gcc

Signed-off-by: Matthew Fortune <matthew.fortune@imgtec.com>
Signed-off-by: Faraz Shahbazker <fshahbazker@wavecomp.com>
Signed-off-by: Aleksandar Rakic <aleksandar.rakic@htecgroup.com>
---
 gcc/config/mips/mips.cc | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index a1208bcef69..dcb4b9f9f99 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -6255,9 +6255,15 @@  mips_output_move (rtx insn, rtx dest, rtx src)
 	switch (GET_MODE_SIZE (mode))
 	  {
 	  case 1: return "sb\t%z1,%0";
-	  case 2: return "sh\t%z1,%0";
-	  case 4: return "sw\t%z1,%0";
-	  case 8: return "sd\t%z1,%0";
+	  case 2: return ((MEM_ALIGN (dest) >= BITS_PER_UNIT * 2)
+			  ? "sh\t%z1,%0"
+			  : "sh\t%z1,%0 # unaligned");
+	  case 4: return ((MEM_ALIGN (dest) >= BITS_PER_UNIT * 4)
+			  ? "sw\t%z1,%0"
+			  : "sw\t%z1,%0 # unaligned");
+	  case 8: return ((MEM_ALIGN (dest) >= BITS_PER_UNIT * 8)
+			  ? "sd\t%z1,%0"
+			  : "sd\t%z1,%0 # unaligned");
 	  default: gcc_unreachable ();
 	  }
     }
@@ -6313,18 +6319,30 @@  mips_output_move (rtx insn, rtx dest, rtx src)
 	    switch (GET_MODE_SIZE (mode))
 	      {
 	      case 1: return "lbu\t$0,%1";
-	      case 2: return "lhu\t$0,%1";
-	      case 4: return "lw\t$0,%1";
-	      case 8: return "ld\t$0,%1";
+	      case 2: return ((MEM_ALIGN (src) >= BITS_PER_UNIT * 2)
+			      ? "lhu\t$0,%1"
+			      : "lhu\t$0,%1 # unaligned");
+	      case 4: return ((MEM_ALIGN (src) >= BITS_PER_UNIT * 4)
+			      ? "lw\t$0,%1"
+			      : "lw\t$0,%1 # unaligned");
+	      case 8: return ((MEM_ALIGN (src) >= BITS_PER_UNIT * 8)
+			      ? "ld\t$0,%1"
+			      : "ld\t$0,%1 # unaligned");
 	      default: gcc_unreachable ();
 	      }
 	  else
 	    switch (GET_MODE_SIZE (mode))
 	      {
 	      case 1: return "lbu\t%0,%1";
-	      case 2: return "lhu\t%0,%1";
-	      case 4: return "lw\t%0,%1";
-	      case 8: return "ld\t%0,%1";
+	      case 2: return ((MEM_ALIGN (src) >= BITS_PER_UNIT * 2)
+			      ? "lhu\t%0,%1"
+			      : "lhu\t%0,%1 # unaligned");
+	      case 4: return ((MEM_ALIGN (src) >= BITS_PER_UNIT * 4)
+			      ? "lw\t%0,%1"
+			      : "lw\t%0,%1 # unaligned");
+	      case 8: return ((MEM_ALIGN (src) >= BITS_PER_UNIT * 8)
+			      ? "ld\t%0,%1"
+			      : "ld\t%0,%1 # unaligned");
 	      default: gcc_unreachable ();
 	      }
 	}