Skip to content

Commit c7d9eab

Browse files
authored
[AVR] Don't apply post-indexing on mismatched pointers (#145224)
fixes #143247
1 parent f78819a commit c7d9eab

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

llvm/lib/Target/AVR/AVRISelLowering.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,14 +1071,17 @@ bool AVRTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
10711071
ISD::MemIndexedMode &AM,
10721072
SelectionDAG &DAG) const {
10731073
EVT VT;
1074+
SDValue Ptr;
10741075
SDLoc DL(N);
10751076

10761077
if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
10771078
VT = LD->getMemoryVT();
1079+
Ptr = LD->getBasePtr();
10781080
if (LD->getExtensionType() != ISD::NON_EXTLOAD)
10791081
return false;
10801082
} else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
10811083
VT = ST->getMemoryVT();
1084+
Ptr = ST->getBasePtr();
10821085
// We can not store to program memory.
10831086
if (AVR::isProgramMemoryAccess(ST))
10841087
return false;
@@ -1115,6 +1118,12 @@ bool AVRTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
11151118
return false;
11161119

11171120
Base = Op->getOperand(0);
1121+
1122+
// Post-indexing updates the base, so it's not a valid transform
1123+
// if that's not the same as the load's pointer.
1124+
if (Ptr != Base)
1125+
return false;
1126+
11181127
Offset = DAG.getConstant(RHSC, DL, MVT::i8);
11191128
AM = ISD::POST_INC;
11201129

llvm/test/CodeGen/AVR/bug-143247.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -O=2 -mtriple=avr-none --mcpu=avr128db28 -verify-machineinstrs | FileCheck %s
3+
4+
declare dso_local void @nil(i16 noundef) addrspace(1)
5+
6+
define void @complex_sbi() {
7+
; CHECK-LABEL: complex_sbi:
8+
; CHECK: ; %bb.0: ; %entry
9+
; CHECK-NEXT: push r16
10+
; CHECK-NEXT: push r17
11+
; CHECK-NEXT: ldi r24, 0
12+
; CHECK-NEXT: ldi r25, 0
13+
; CHECK-NEXT: .LBB0_1: ; %while.cond
14+
; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
15+
; CHECK-NEXT: sbi 1, 7
16+
; CHECK-NEXT: adiw r24, 1
17+
; CHECK-NEXT: movw r16, r24
18+
; CHECK-NEXT: andi r24, 15
19+
; CHECK-NEXT: andi r25, 0
20+
; CHECK-NEXT: adiw r24, 1
21+
; CHECK-NEXT: call nil
22+
; CHECK-NEXT: movw r24, r16
23+
; CHECK-NEXT: rjmp .LBB0_1
24+
entry:
25+
br label %while.cond
26+
while.cond:
27+
%s.0 = phi i16 [ 0, %entry ], [ %inc, %while.cond ]
28+
%inc = add nuw nsw i16 %s.0, 1
29+
%0 = load volatile i8, ptr inttoptr (i16 1 to ptr), align 1
30+
%or = or i8 %0, -128
31+
store volatile i8 %or, ptr inttoptr (i16 1 to ptr), align 1
32+
%and = and i16 %inc, 15
33+
%add = add nuw nsw i16 %and, 1
34+
tail call addrspace(1) void @nil(i16 noundef %add)
35+
br label %while.cond
36+
}

0 commit comments

Comments
 (0)