Skip to content

Commit 9f29007

Browse files
authored
[AVR] Force to emit relocation slots for relative branch instructions (#145291)
fixes #133579
1 parent bbbbc09 commit 9f29007

26 files changed

+163
-115
lines changed

llvm/lib/Target/AVR/MCTargetDesc/AVRAsmBackend.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -514,19 +514,7 @@ bool AVRAsmBackend::forceRelocation(const MCFragment &F, const MCFixup &Fixup,
514514
return false;
515515

516516
case AVR::fixup_7_pcrel:
517-
case AVR::fixup_13_pcrel: {
518-
uint64_t Offset = Target.getConstant();
519-
uint64_t Size = AVRAsmBackend::getFixupKindInfo(Fixup.getKind()).TargetSize;
520-
521-
// If the jump is too large to encode it, fall back to a relocation.
522-
//
523-
// Note that trying to actually link that relocation *would* fail, but the
524-
// hopes are that the module we're currently compiling won't be actually
525-
// linked to the final binary.
526-
return !adjust::adjustRelativeBranch(Size, Fixup, Offset,
527-
getContext().getSubtargetInfo());
528-
}
529-
517+
case AVR::fixup_13_pcrel:
530518
case AVR::fixup_call:
531519
return true;
532520
}

llvm/test/CodeGen/AVR/branch-relaxation-long-backward.ll

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
; RUN: llc < %s -mtriple=avr -mcpu=attiny85 -filetype=obj -o - | llvm-objdump --mcpu=attiny85 -dr --no-show-raw-insn --no-leading-addr - | FileCheck --check-prefix=ATTINY85 %s
2-
; RUN: llc < %s -mtriple=avr -mcpu=avr25 -filetype=obj -o - | llvm-objdump --mcpu=avr25 -dr --no-show-raw-insn --no-leading-addr - | FileCheck --check-prefix=AVR25 %s
32
; RUN: llc < %s -mtriple=avr -mcpu=avr3 -filetype=obj -o - | llvm-objdump --mcpu=avr3 -dr --no-show-raw-insn --no-leading-addr - | FileCheck --check-prefix=AVR3 %s
43

54
; ATTINY85: <main>:
65
; ATTINY85-NEXT: andi r24, 0x1
76
; ATTINY85: cpi r24, 0x0
8-
; ATTINY85-NEXT: breq .+2
9-
; ATTINY85-NEXT: rjmp .+4086
7+
; ATTINY85-NEXT: breq .-2
8+
; ATTINY85-NEXT: R_AVR_7_PCREL .text+0x100c
9+
; ATTINY85-NEXT: rjmp .-2
10+
; ATTINY85-NEXT: R_AVR_13_PCREL .text+0x2
1011
; ATTINY85: ldi r24, 0x3
1112
; ATTINY85-NEXT: ret
1213

13-
; AVR25: <main>:
14-
; AVR25-NEXT: andi r24, 0x1
15-
; AVR25: cpi r24, 0x0
16-
; AVR25-NEXT: breq .+2
17-
; AVR25-NEXT: rjmp .-2
18-
; AVR25-NEXT: R_AVR_13_PCREL .text+0x2
19-
; AVR25: ldi r24, 0x3
20-
; AVR25-NEXT: ret
21-
2214
; AVR3: <main>:
2315
; AVR3-NEXT: andi r24, 0x1
2416
; AVR3: cpi r24, 0x0
25-
; AVR3-NEXT: breq .+4
17+
; AVR3-NEXT: breq .-2
18+
; AVR3-NEXT: R_AVR_7_PCREL .text+0x100e
2619
; AVR3-NEXT: jmp 0x0
2720
; AVR3-NEXT: R_AVR_CALL .text+0x2
2821
; AVR3: ldi r24, 0x3

llvm/test/CodeGen/AVR/branch-relaxation-long-forward.ll

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
; RUN: llc < %s -mtriple=avr -mcpu=attiny85 -filetype=obj -o - | llvm-objdump --mcpu=attiny85 -dr --no-show-raw-insn --no-leading-addr - | FileCheck --check-prefix=ATTINY85 %s
2-
; RUN: llc < %s -mtriple=avr -mcpu=avr25 -filetype=obj -o - | llvm-objdump --mcpu=avr25 -dr --no-show-raw-insn --no-leading-addr - | FileCheck --check-prefix=AVR25 %s
32
; RUN: llc < %s -mtriple=avr -mcpu=avr3 -filetype=obj -o - | llvm-objdump --mcpu=avr3 -dr --no-show-raw-insn --no-leading-addr - | FileCheck --check-prefix=AVR3 %s
43

54
; ATTINY85: <main>:
65
; ATTINY85-NEXT: andi r24, 0x1
76
; ATTINY85-NEXT: cpi r24, 0x0
8-
; ATTINY85-NEXT: brne .+2
9-
; ATTINY85-NEXT: rjmp .-4092
7+
; ATTINY85-NEXT: brne .-2
8+
; ATTINY85-NEXT: R_AVR_7_PCREL .text+0x8
9+
; ATTINY85-NEXT: rjmp .-2
10+
; ATTINY85-NEXT: R_AVR_13_PCREL .text+0x100c
1011
; ATTINY85: ldi r24, 0x3
1112
; ATTINY85-NEXT: ret
1213

13-
; AVR25: <main>:
14-
; AVR25-NEXT: andi r24, 0x1
15-
; AVR25-NEXT: cpi r24, 0x0
16-
; AVR25-NEXT: brne .+2
17-
; AVR25-NEXT: rjmp .-2
18-
; AVR25-NEXT: R_AVR_13_PCREL .text+0x100c
19-
; AVR25: ldi r24, 0x3
20-
; AVR25-NEXT: ret
21-
2214
; AVR3: <main>:
2315
; AVR3-NEXT: andi r24, 0x1
2416
; AVR3-NEXT: cpi r24, 0x0
25-
; AVR3-NEXT: brne .+4
17+
; AVR3-NEXT: brne .-2
18+
; AVR3-NEXT: R_AVR_7_PCREL .text+0xa
2619
; AVR3-NEXT: jmp 0x0
2720
; AVR3-NEXT: R_AVR_CALL .text+0x100e
2821
; AVR3: ldi r24, 0x3

llvm/test/CodeGen/AVR/jmp.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ declare i8 @bar(i8);
1818
; CHECK: rcall .-2
1919
; CHECK-NEXT: 00000000: R_AVR_13_PCREL bar
2020
; CHECK-NEXT: cpi r24, 0x7b
21-
; CHECK-NEXT: brne .+4
21+
; CHECK-NEXT: brne .-2
22+
; CHECK-NEXT: R_AVR_7_PCREL .text+0xa
2223
; CHECK-NEXT: ldi r24, 0x64
2324
; CHECK-NEXT: ret
2425
; CHECK-NEXT: ldi r24, 0xc8

llvm/test/MC/AVR/inst-brbc.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ foo:
1515
; CHECK: brcc .Ltmp1-16+2 ; encoding: [0bAAAAA000,0b111101AA]
1616

1717
; INST-LABEL: <foo>:
18-
; INST-NEXT: 23 f4 brvc .+8
19-
; INST-NEXT: c0 f7 brsh .-16
18+
; INST-NEXT: fb f7 brvc .-2
19+
; INST-NEXT: R_AVR_7_PCREL .text+0xa
20+
; INST-NEXT: f8 f7 brsh .-2
21+
; INST-NEXT: R_AVR_7_PCREL .text-0xc
2022
; INST-NEXT: 59 f7 brne .-42
2123
; INST-NEXT: 52 f7 brpl .-44
2224
; INST-NEXT: 4c f7 brge .-46

llvm/test/MC/AVR/inst-brbs.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ foo:
1414
; CHECK: brcs .Ltmp1-12+2 ; encoding: [0bAAAAA000,0b111100AA]
1515

1616
; INST-LABEL: <foo>:
17-
; INST-NEXT: 23 f0 brvs .+8
18-
; INST-NEXT: d0 f3 brlo .-12
17+
; INST-NEXT: fb f3 brvs .-2
18+
; INST-NEXT: R_AVR_7_PCREL .text+0xa
19+
; INST-NEXT: f8 f3 brlo .-2
20+
; INST-NEXT: R_AVR_7_PCREL .text-0x8
1921
; INST-NEXT: 59 f3 breq .-42
2022
; INST-NEXT: 52 f3 brmi .-44
2123
; INST-NEXT: 4c f3 brlt .-46

llvm/test/MC/AVR/inst-brcc.s

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ bar:
1818
; CHECK: brcc bar ; encoding: [0bAAAAA000,0b111101AA]
1919

2020
; INST-LABEL: <foo>:
21-
; INST-NEXT: 08 f5 brsh .+66
22-
; INST-NEXT: a8 f7 brsh .-22
23-
; INST-NEXT: 08 f5 brsh .+66
24-
; INST-NEXT: 00 f4 brsh .+0
21+
; INST-NEXT: f8 f7 brsh .-2
22+
; INST-NEXT: R_AVR_7_PCREL .text+0x44
23+
; INST-NEXT: f8 f7 brsh .-2
24+
; INST-NEXT: R_AVR_7_PCREL .text-0x12
25+
; INST-NEXT: f8 f7 brsh .-2
26+
; INST-NEXT: R_AVR_7_PCREL .text+0x48
27+
; INST-NEXT: f8 f7 brsh .-2
28+
; INST-NEXT: R_AVR_7_PCREL .text+0x8

llvm/test/MC/AVR/inst-brcs.s

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ bar:
1818
; CHECK: brcs bar ; encoding: [0bAAAAA000,0b111100AA]
1919

2020
; INST-LABEL: <foo>:
21-
; INST-NEXT: 20 f0 brlo .+8
22-
; INST-NEXT: 10 f0 brlo .+4
23-
; INST-NEXT: 20 f0 brlo .+8
24-
; INST-NEXT: 00 f0 brlo .+0
21+
; INST-NEXT: f8 f3 brlo .-2
22+
; INST-NEXT: R_AVR_7_PCREL .text+0xa
23+
; INST-NEXT: f8 f3 brlo .-2
24+
; INST-NEXT: R_AVR_7_PCREL .text+0x8
25+
; INST-NEXT: f8 f3 brlo .-2
26+
; INST-NEXT: R_AVR_7_PCREL .text+0xe
27+
; INST-NEXT: f8 f3 brlo .-2
28+
; INST-NEXT: R_AVR_7_PCREL .text+0x8

llvm/test/MC/AVR/inst-breq.s

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ bar:
1818
; CHECK: brbs 1, bar ; encoding: [0bAAAAA001,0b111100AA]
1919

2020
; INST-LABEL: <foo>:
21-
; INST-NEXT: b9 f3 breq .-18
22-
; INST-NEXT: d1 f3 breq .-12
23-
; INST-NEXT: b9 f3 breq .-18
24-
; INST-NEXT: 01 f0 breq .+0
21+
; INST-NEXT: f9 f3 breq .-2
22+
; INST-NEXT: R_AVR_7_PCREL .text-0x10
23+
; INST-NEXT: f9 f3 breq .-2
24+
; INST-NEXT: R_AVR_7_PCREL .text-0x8
25+
; INST-NEXT: f9 f3 breq .-2
26+
; INST-NEXT: R_AVR_7_PCREL .text-0xc
27+
; INST-NEXT: f9 f3 breq .-2

llvm/test/MC/AVR/inst-brge.s

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ bar:
1616
; CHECK: brge bar ; encoding: [0bAAAAA100,0b111101AA]
1717

1818
; INST-LABEL: <foo>:
19-
; INST-NEXT: cc f4 brge .+50
20-
; INST-NEXT: ac f4 brge .+42
21-
; INST-NEXT: 04 f4 brge .+0
19+
; INST-NEXT: fc f7 brge .-2
20+
; INST-NEXT: R_AVR_7_PCREL .text+0x34
21+
; INST-NEXT: fc f7 brge .-2
22+
; INST-NEXT: R_AVR_7_PCREL .text+0x2e
23+
; INST-NEXT: fc f7 brge .-2
24+
; INST-NEXT: R_AVR_7_PCREL .text+0x6

0 commit comments

Comments
 (0)