RISC-V: Only relax to C.LUI when imm != 0 and rd != 0/2
[deliverable/binutils-gdb.git] / bfd / elfnn-riscv.c
index f7cdb4e2b0f9451fa5d4e48bb5a629a74e80873d..b6e389270f59cbb3250a47124f175ebbfa686f72 100644 (file)
@@ -2988,9 +2988,10 @@ _bfd_riscv_relax_lui (bfd *abfd,
       && VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (symval))
       && VALID_RVC_LUI_IMM (RISCV_CONST_HIGH_PART (symval + ELF_MAXPAGESIZE)))
     {
-      /* Replace LUI with C.LUI if legal (i.e., rd != x2/sp).  */
+      /* Replace LUI with C.LUI if legal (i.e., rd != x0 and rd != x2/sp).  */
       bfd_vma lui = bfd_get_32 (abfd, contents + rel->r_offset);
-      if (((lui >> OP_SH_RD) & OP_MASK_RD) == X_SP)
+      unsigned rd = ((unsigned)lui >> OP_SH_RD) & OP_MASK_RD;
+      if (rd == 0 || rd == X_SP)
        return TRUE;
 
       lui = (lui & (OP_MASK_RD << OP_SH_RD)) | MATCH_C_LUI;
This page took 0.027247 seconds and 4 git commands to generate.