Skip to content

Commit

Permalink
Merge pull request #14 from MediaTek-Labs/fix/volatile-swm
Browse files Browse the repository at this point in the history
Avoid swm/lwm of volatile accesses.
  • Loading branch information
cme authored Jul 6, 2023
2 parents 9e78483 + 1e75b90 commit 7e8b44f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions llvm/lib/Target/Mips/NanoMipsLoadStoreOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ unsigned NMLoadStoreOpt::getRegNo(unsigned Reg) {

bool NMLoadStoreOpt::isValidLoadStore(MachineInstr &MI, bool IsLoad) {
unsigned Opcode = MI.getOpcode();

// Make sure the instruction doesn't have any atomic, volatile or
// otherwise strictly ordered accesses.
for (auto &MMO : MI.memoperands())
if (MMO->isAtomic() || !MMO->isUnordered())
return false;

if (IsLoad) {
// TODO: Handle unaligned loads and stores.
if (Opcode == Mips::LW_NM || Opcode == Mips::LWs9_NM) {
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/Mips/nanomips/test-volatile-swm.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: llc -march=nanomips < %s | FileCheck %s
target datalayout = "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32:64-S128"
target triple = "nanomips"

%struct.S = type { i32, i32 }

declare dso_local inreg { i32, i32 } @GetStruct(...) local_unnamed_addr

define dso_local void @test(%struct.S* %p, i32 signext %i) local_unnamed_addr {
entry:
; CHECK-NOT: swm
; CHECK: sw
; CHECK: sw
%call = tail call inreg { i32, i32 } bitcast ({ i32, i32 } (...)* @GetStruct to { i32, i32 } ()*)()
%0 = extractvalue { i32, i32 } %call, 0
%1 = extractvalue { i32, i32 } %call, 1
%B1 = getelementptr inbounds %struct.S, %struct.S* %p, i32 0, i32 1
store volatile i32 %1, i32* %B1, align 4
%A26 = bitcast %struct.S* %p to i32*
store volatile i32 %0, i32* %A26, align 4
ret void
}

0 comments on commit 7e8b44f

Please sign in to comment.