diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.h b/llvm/lib/Target/AMDGPU/SIISelLowering.h --- a/llvm/lib/Target/AMDGPU/SIISelLowering.h +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.h @@ -273,6 +273,12 @@ bool isShuffleMaskLegal(ArrayRef /*Mask*/, EVT /*VT*/) const override; + // While address space 7 should never make it to codegen, it still needs to + // have a MVT to prevent some analyses that query this function from breaking, + // so lie and say that they fit into 128 bits. + MVT getPointerTy(const DataLayout &DL, unsigned AS) const override; + MVT getPointerMemTy(const DataLayout &DL, unsigned AS) const override; + bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, MachineFunction &MF, unsigned IntrinsicID) const override; diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -979,6 +979,24 @@ return memVTFromLoadIntrData(ST->getContainedType(0), MaxNumLanes); } +/// Map address space 7 to MVT::i128 because that's its in-memory +/// representation. This doesn't ultimately matter because address space 7 +/// pointers should all be eliminated by codegen time, but there are analyses +/// that, ultimately, depend on all pointers mapping to a MachineValueType. This +/// is a lie, since the pointers are bigger than that, but it'll give cost +/// models reasonable numbers to work with without being too out-there. +MVT SITargetLowering::getPointerTy(const DataLayout &DL, unsigned AS) const { + if (AMDGPUAS::BUFFER_FAT_POINTER == AS && DL.getPointerSizeInBits(AS) > 128) + return MVT::i128; + return AMDGPUTargetLowering::getPointerTy(DL, AS); +} + +MVT SITargetLowering::getPointerMemTy(const DataLayout &DL, unsigned AS) const { + if (AMDGPUAS::BUFFER_FAT_POINTER == AS && DL.getPointerSizeInBits(AS) > 128) + return MVT::i128; + return AMDGPUTargetLowering::getPointerMemTy(DL, AS); +} + bool SITargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, const CallInst &CI, MachineFunction &MF, diff --git a/llvm/test/Transforms/IndVarSimplify/AMDGPU/addrspace-7-doesnt-crash.ll b/llvm/test/Transforms/IndVarSimplify/AMDGPU/addrspace-7-doesnt-crash.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/IndVarSimplify/AMDGPU/addrspace-7-doesnt-crash.ll @@ -0,0 +1,31 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2 +; RUN: opt -passes=indvars -S < %s | FileCheck %s + +target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8" +target triple = "amdgcn--amdpal" + +define void @f(ptr addrspace(7) %arg) { +; CHECK-LABEL: define void @f +; CHECK-SAME: (ptr addrspace(7) [[ARG:%.*]]) { +; CHECK-NEXT: bb: +; CHECK-NEXT: br label [[BB1:%.*]] +; CHECK: bb1: +; CHECK-NEXT: br i1 false, label [[BB2:%.*]], label [[BB1]] +; CHECK: bb2: +; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr addrspace(7) [[ARG]], i32 8 +; CHECK-NEXT: br label [[BB3:%.*]] +; CHECK: bb3: +; CHECK-NEXT: [[I4:%.*]] = load i32, ptr addrspace(7) [[SCEVGEP]], align 4 +; CHECK-NEXT: br label [[BB3]] +; +bb: + br label %bb1 +bb1: + %i = getelementptr i32, ptr addrspace(7) %arg, i32 2 + br i1 false, label %bb2, label %bb1 +bb2: + br label %bb3 +bb3: + %i4 = load i32, ptr addrspace(7) %i, align 4 + br label %bb3 +}