Skip to content

Commit

Permalink
Fix extended/indexed loads and truncated/indexed stores
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Jul 31, 2024
1 parent 8c2787d commit dbd3e84
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
14 changes: 8 additions & 6 deletions llvm/lib/Target/V810/V810ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,9 +891,9 @@ static SDValue PerformLoadCombine(SDNode *N,
SDValue GlobalAddr = BuildMovhiMoveaPair(DAG, GA, DL, PtrType, 0);
SDValue ConstOffset = DAG.getConstant(APInt(32, Offset, true), DL, PtrType);
SDValue BasePtr = DAG.getMemBasePlusOffset(GlobalAddr, ConstOffset, DL, LD->getFlags());
return DAG.getLoad(LD->getValueType(0), DL, LD->getChain(), BasePtr,
LD->getPointerInfo(), LD->getAlign(),
LD->getMemOperand()->getFlags(), LD->getAAInfo());
return DAG.getLoad(LD->getAddressingMode(), LD->getExtensionType(),
LD->getValueType(0), DL, LD->getChain(), BasePtr, LD->getOffset(),
LD->getMemoryVT(), LD->getMemOperand());
}

// Instead of generating code like:
Expand Down Expand Up @@ -929,9 +929,11 @@ static SDValue PerformStoreCombine(SDNode *N,
SDValue GlobalAddr = BuildMovhiMoveaPair(DAG, GA, DL, PtrType, 0);
SDValue ConstOffset = DAG.getConstant(APInt(32, Offset, true), DL, PtrType);
SDValue BasePtr = DAG.getMemBasePlusOffset(GlobalAddr, ConstOffset, DL, ST->getFlags());
return DAG.getStore(ST->getChain(), DL, ST->getValue(), BasePtr,
ST->getPointerInfo(), ST->getAlign(),
ST->getMemOperand()->getFlags(), ST->getAAInfo());
SDValue NewST = DAG.getTruncStore(ST->getChain(), DL, ST->getValue(), BasePtr, ST->getMemoryVT(), ST->getMemOperand());
if (ST->isIndexed()) {
NewST = DAG.getIndexedStore(NewST, DL, BasePtr, ST->getOffset(), ST->getAddressingMode());
}
return NewST;
}

SDValue V810TargetLowering::
Expand Down
39 changes: 39 additions & 0 deletions llvm/test/CodeGen/V810/gprel.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
; RUN: llc < %s -mtriple=v810 -mattr=+gprel | FileCheck %s -check-prefix=GPREL
; RUN: llc < %s -mtriple=v810 -mattr=-gprel | FileCheck %s -check-prefix=NO-GPREL

%SomeStruct = type { i32, i16, i16 }

@mutable_global = external dso_local global [4 x i32], align 4
@mutable_global_struct = external dso_local global %SomeStruct, align 4
@immutable_global = external dso_local constant i32, align 4

define i32 @test_gprel_read() {
Expand Down Expand Up @@ -39,6 +42,24 @@ entry:
ret i32 %0
}

define i32 @test_gprel_read_offset_nonword() {
; GPREL-LABEL: test_gprel_read_offset_nonword:
; GPREL: # %bb.0: # %entry
; GPREL-NEXT: ld.h sdaoff(mutable_global_struct+4)[r4], r10
; GPREL-NEXT: jmp [r31]
;
; NO-GPREL-LABEL: test_gprel_read_offset_nonword:
; NO-GPREL: # %bb.0: # %entry
; NO-GPREL-NEXT: movhi hi(mutable_global_struct), r0, r6
; NO-GPREL-NEXT: movea lo(mutable_global_struct), r6, r6
; NO-GPREL-NEXT: ld.h 4[r6], r10
; NO-GPREL-NEXT: jmp [r31]
entry:
%0 = load i16, ptr getelementptr inbounds (%SomeStruct, ptr @mutable_global_struct, i32 0, i32 1), align 4
%conv = sext i16 %0 to i32
ret i32 %conv
}

define void @test_gprel_write(i32 %value) {
; GPREL-LABEL: test_gprel_write:
; GPREL: # %bb.0: # %entry
Expand Down Expand Up @@ -73,6 +94,24 @@ entry:
ret void
}

define void @test_gprel_write_offset_nonword(i32 %value) {
; GPREL-LABEL: test_gprel_write_offset_nonword:
; GPREL: # %bb.0: # %entry
; GPREL-NEXT: st.h r6, sdaoff(mutable_global_struct+4)[r4]
; GPREL-NEXT: jmp [r31]
;
; NO-GPREL-LABEL: test_gprel_write_offset_nonword:
; NO-GPREL: # %bb.0: # %entry
; NO-GPREL-NEXT: movhi hi(mutable_global_struct), r0, r7
; NO-GPREL-NEXT: movea lo(mutable_global_struct), r7, r7
; NO-GPREL-NEXT: st.h r6, 4[r7]
; NO-GPREL-NEXT: jmp [r31]
entry:
%0 = trunc i32 %value to i16
store i16 %0, ptr getelementptr inbounds (i8, ptr @mutable_global_struct, i32 4), align 4
ret void
}

define i32 @test_const_read() {
; GPREL-LABEL: test_const_read:
; GPREL: # %bb.0: # %entry
Expand Down

0 comments on commit dbd3e84

Please sign in to comment.