[llvm] c7d9eab - [AVR] Don't apply post-indexing on mismatched pointers (#145224)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 22 03:18:04 PDT 2025
Author: Patryk Wychowaniec
Date: 2025-06-22T18:18:00+08:00
New Revision: c7d9eabf4a9c1c8c70b5976ea775fd3d143e93f7
URL: https://github.com/llvm/llvm-project/commit/c7d9eabf4a9c1c8c70b5976ea775fd3d143e93f7
DIFF: https://github.com/llvm/llvm-project/commit/c7d9eabf4a9c1c8c70b5976ea775fd3d143e93f7.diff
LOG: [AVR] Don't apply post-indexing on mismatched pointers (#145224)
fixes https://github.com/llvm/llvm-project/issues/143247
Added:
llvm/test/CodeGen/AVR/bug-143247.ll
Modified:
llvm/lib/Target/AVR/AVRISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AVR/AVRISelLowering.cpp b/llvm/lib/Target/AVR/AVRISelLowering.cpp
index 9747ad0c5cd58..3955f2a252e76 100644
--- a/llvm/lib/Target/AVR/AVRISelLowering.cpp
+++ b/llvm/lib/Target/AVR/AVRISelLowering.cpp
@@ -1071,14 +1071,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;
@@ -1115,6 +1118,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;
diff --git a/llvm/test/CodeGen/AVR/bug-143247.ll b/llvm/test/CodeGen/AVR/bug-143247.ll
new file mode 100644
index 0000000000000..07c4c6562c950
--- /dev/null
+++ b/llvm/test/CodeGen/AVR/bug-143247.ll
@@ -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
+}
More information about the llvm-commits
mailing list