From 41517aa3f4e4d2212e6af71e7d97400fc137260c Mon Sep 17 00:00:00 2001 From: Daniel Sanders Date: Tue, 8 Sep 2015 09:07:03 +0000 Subject: [PATCH] [mips] Reserve address spaces 1-255 for software use. Summary: And define them to have noop casts with address spaces 0-255. Reviewers: pekka.jaaskelainen Subscribers: pekka.jaaskelainen, llvm-commits Differential Revision: http://reviews.llvm.org/D12678 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246990 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/Mips/MipsISelLowering.h | 8 ++++++++ test/CodeGen/Mips/llvm-ir/addrspacecast.ll | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/CodeGen/Mips/llvm-ir/addrspacecast.ll diff --git a/lib/Target/Mips/MipsISelLowering.h b/lib/Target/Mips/MipsISelLowering.h index 1ec0d2c618f..b0204ca516d 100644 --- a/lib/Target/Mips/MipsISelLowering.h +++ b/lib/Target/Mips/MipsISelLowering.h @@ -269,6 +269,14 @@ namespace llvm { unsigned getRegisterByName(const char* RegName, EVT VT, SelectionDAG &DAG) const override; + /// Returns true if a cast between SrcAS and DestAS is a noop. + bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override { + // Mips doesn't have any special address spaces so we just reserve + // the first 256 for software use (e.g. OpenCL) and treat casts + // between them as noops. + return SrcAS < 256 && DestAS < 256; + } + protected: SDValue getGlobalReg(SelectionDAG &DAG, EVT Ty) const; diff --git a/test/CodeGen/Mips/llvm-ir/addrspacecast.ll b/test/CodeGen/Mips/llvm-ir/addrspacecast.ll new file mode 100644 index 00000000000..060fa4ce7bb --- /dev/null +++ b/test/CodeGen/Mips/llvm-ir/addrspacecast.ll @@ -0,0 +1,12 @@ +; RUN: llc < %s -march=mips -mcpu=mips2 | FileCheck %s -check-prefix=ALL + +; Address spaces 1-255 are software defined. +define i32* @cast(i32 *%arg) { + %1 = addrspacecast i32* %arg to i32 addrspace(1)* + %2 = addrspacecast i32 addrspace(1)* %1 to i32 addrspace(2)* + %3 = addrspacecast i32 addrspace(2)* %2 to i32 addrspace(0)* + ret i32* %3 +} + +; ALL-LABEL: cast: +; ALL: move $2, $4 -- 2.34.1