Skip to content

Backport #145224 #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions llvm/lib/Target/AVR/AVRISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1123,14 +1123,17 @@ bool AVRTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
ISD::MemIndexedMode &AM,
SelectionDAG &DAG) const {
EVT VT;
SDValue Ptr;
SDLoc DL(N);

if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
VT = LD->getMemoryVT();
Ptr = LD->getBasePtr();
if (LD->getExtensionType() != ISD::NON_EXTLOAD)
return false;
} else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
VT = ST->getMemoryVT();
Ptr = ST->getBasePtr();
// We can not store to program memory.
if (AVR::isProgramMemoryAccess(ST))
return false;
Expand Down Expand Up @@ -1167,6 +1170,12 @@ bool AVRTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
return false;

Base = Op->getOperand(0);

// Post-indexing updates the base, so it's not a valid transform
// if that's not the same as the load's pointer.
if (Ptr != Base)
return false;

Offset = DAG.getConstant(RHSC, DL, MVT::i8);
AM = ISD::POST_INC;

Expand Down
36 changes: 36 additions & 0 deletions llvm/test/CodeGen/AVR/bug-143247.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -O=2 -mtriple=avr-none --mcpu=avr128db28 -verify-machineinstrs | FileCheck %s

declare dso_local void @nil(i16 noundef) addrspace(1)

define void @complex_sbi() {
; CHECK-LABEL: complex_sbi:
; CHECK: ; %bb.0: ; %entry
; CHECK-NEXT: push r16
; CHECK-NEXT: push r17
; CHECK-NEXT: ldi r24, 0
; CHECK-NEXT: ldi r25, 0
; CHECK-NEXT: .LBB0_1: ; %while.cond
; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
; CHECK-NEXT: sbi 1, 7
; CHECK-NEXT: adiw r24, 1
; CHECK-NEXT: movw r16, r24
; CHECK-NEXT: andi r24, 15
; CHECK-NEXT: andi r25, 0
; CHECK-NEXT: adiw r24, 1
; CHECK-NEXT: call nil
; CHECK-NEXT: movw r24, r16
; CHECK-NEXT: rjmp .LBB0_1
entry:
br label %while.cond
while.cond:
%s.0 = phi i16 [ 0, %entry ], [ %inc, %while.cond ]
%inc = add nuw nsw i16 %s.0, 1
%0 = load volatile i8, ptr inttoptr (i16 1 to ptr), align 1
%or = or i8 %0, -128
store volatile i8 %or, ptr inttoptr (i16 1 to ptr), align 1
%and = and i16 %inc, 15
%add = add nuw nsw i16 %and, 1
tail call addrspace(1) void @nil(i16 noundef %add)
br label %while.cond
}