File tree Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Expand file tree Collapse file tree 2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -393,17 +393,25 @@ legitimate_small_data_address_p (rtx x, machine_mode mode)
393393 if (!CONST_INT_P (XEXP (x, 1 )))
394394 return false ;
395395
396- /* Small data relocs works with scalled addresses, check if
396+ const int offset = INTVAL (XEXP (x, 1 ));
397+ int size = GET_MODE_SIZE (mode);
398+ size = size == 8 ? 4 : size;
399+
400+ /* Reloc allows scaled signed 9 bits. */
401+ const int v = (offset / size) >> 8 ;
402+ if (v != 0 && v != -1 )
403+ return false ;
404+
405+ /* Small data relocs works with scaled addresses, check if
397406 the immediate fits the requirements. */
398- switch (GET_MODE_SIZE (mode) )
407+ switch (size )
399408 {
400409 case 1 :
401410 return p0;
402411 case 2 :
403- return p0 && ((INTVAL ( XEXP (x, 1 )) & 0x1 ) == 0 );
412+ return p0 && ((offset & 0x1 ) == 0 );
404413 case 4 :
405- case 8 :
406- return p0 && ((INTVAL (XEXP (x, 1 )) & 0x3 ) == 0 );
414+ return p0 && ((offset & 0x3 ) == 0 );
407415 default :
408416 return false ;
409417 }
Original file line number Diff line number Diff line change 1+ /* { dg-do compile } */
2+ /* { dg-options "-O2 -msdata" } */
3+
4+ __attribute__((section (".sdata" ))) int a [300 ];
5+
6+ int f (void )
7+ {
8+ return a [255 ];
9+ }
10+
11+ int g (void )
12+ {
13+ return a [256 ];
14+ }
15+
16+ /* { dg-final { scan-assembler "ld.as\\s+r0,\\\[gp,@a@sda\+1020\\\]" } } */
17+ /* { dg-final { scan-assembler "ld\\s+r0,\\\[@a\+1024\\\]" } } */
You can’t perform that action at this time.
0 commit comments