Skip to content

[AVR] Fix incorrect selection of post indexed addresses #145040

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

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 14 additions & 0 deletions llvm/lib/Target/AVR/AVRISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,22 @@ bool AVRTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op,
if (AVR::isProgramMemoryAccess(LD))
return false;

SDValue Ptr;
if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) {
Ptr = LD->getBasePtr();
} else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Ptr = ST->getBasePtr();
} else
return false;

Base = Op->getOperand(0);
Offset = DAG.getConstant(RHSC, DL, MVT::i8);

// 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;

AM = ISD::POST_INC;

return true;
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/AVR/issue-145040.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: llc < %s -O=2 -mtriple=avr-none --mcpu=avr128db28 -verify-machineinstrs | FileCheck %s

declare dso_local void @nil(i16 noundef) local_unnamed_addr addrspace(1) #1
!3 = !{!4, !4, i64 0}
!4 = !{!"omnipotent char", !5, i64 0}
!5 = !{!"Simple C/C++ TBAA"}

define void @complex_sbi() {
; CHECK: sbi 1, 7
entry:
br label %while.cond
while.cond: ; preds = %while.cond, %entry
%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, !tbaa !3
%or = or i8 %0, -128
store volatile i8 %or, ptr inttoptr (i16 1 to ptr), align 1, !tbaa !3
%and = and i16 %inc, 15
%add = add nuw nsw i16 %and, 1
tail call addrspace(1) void @nil(i16 noundef %add) #2
br label %while.cond
}