[llvm] cb3a6bd - [AMDGPULowerBufferFatPointers] Restore zero offset special case
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 01:30:33 PDT 2024
Author: Nikita Popov
Date: 2024-06-12T10:30:23+02:00
New Revision: cb3a6bded74c8c508943e95e5913b8831ab77067
URL: https://github.com/llvm/llvm-project/commit/cb3a6bded74c8c508943e95e5913b8831ab77067
DIFF: https://github.com/llvm/llvm-project/commit/cb3a6bded74c8c508943e95e5913b8831ab77067.diff
LOG: [AMDGPULowerBufferFatPointers] Restore zero offset special case
OffAccum will never be nullptr now, instead check for a zero
constant.
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-pointer-ops.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
index 77238d184adb0..ea654dbd487bc 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
@@ -1388,6 +1388,7 @@ PtrParts SplitPtrStructs::visitAtomicCmpXchgInst(AtomicCmpXchgInst &AI) {
}
PtrParts SplitPtrStructs::visitGetElementPtrInst(GetElementPtrInst &GEP) {
+ using namespace llvm::PatternMatch;
Value *Ptr = GEP.getPointerOperand();
if (!isSplitFatPtr(Ptr->getType()))
return {nullptr, nullptr};
@@ -1405,7 +1406,7 @@ PtrParts SplitPtrStructs::visitGetElementPtrInst(GetElementPtrInst &GEP) {
GEP.mutateType(FatPtrTy);
Value *OffAccum = emitGEPOffset(&IRB, DL, &GEP);
GEP.mutateType(Ptr->getType());
- if (!OffAccum) { // Constant-zero offset
+ if (match(OffAccum, m_Zero())) { // Constant-zero offset
SplitUsers.insert(&GEP);
return {Rsrc, Off};
}
@@ -1415,7 +1416,7 @@ PtrParts SplitPtrStructs::visitGetElementPtrInst(GetElementPtrInst &GEP) {
HasNonNegativeOff = !CI->isNegative();
}
Value *NewOff;
- if (PatternMatch::match(Off, PatternMatch::is_zero())) {
+ if (match(Off, m_Zero())) {
NewOff = OffAccum;
} else {
NewOff = IRB.CreateAdd(Off, OffAccum, "",
diff --git a/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-pointer-ops.ll b/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-pointer-ops.ll
index 60c6890689ccb..35999842d6d71 100644
--- a/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-pointer-ops.ll
+++ b/llvm/test/CodeGen/AMDGPU/lower-buffer-fat-pointers-pointer-ops.ll
@@ -94,10 +94,9 @@ define ptr addrspace(7) @zero_gep(ptr addrspace(7) %ptr) {
; CHECK-SAME: ({ ptr addrspace(8), i32 } [[PTR:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[PTR_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 0
; CHECK-NEXT: [[PTR_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[PTR]], 1
-; CHECK-NEXT: [[RET:%.*]] = add i32 [[PTR_OFF]], 0
; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { ptr addrspace(8), i32 } poison, ptr addrspace(8) [[PTR_RSRC]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = insertvalue { ptr addrspace(8), i32 } [[TMP1]], i32 [[RET]], 1
-; CHECK-NEXT: ret { ptr addrspace(8), i32 } [[TMP2]]
+; CHECK-NEXT: [[RET:%.*]] = insertvalue { ptr addrspace(8), i32 } [[TMP1]], i32 [[PTR_OFF]], 1
+; CHECK-NEXT: ret { ptr addrspace(8), i32 } [[RET]]
;
%ret = getelementptr i8, ptr addrspace(7) %ptr, i32 0
ret ptr addrspace(7) %ret
@@ -109,10 +108,9 @@ define ptr addrspace(7) @zero_gep_goes_second(ptr addrspace(7) %v0, i32 %arg) {
; CHECK-NEXT: [[V0_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[V0]], 0
; CHECK-NEXT: [[V0_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[V0]], 1
; CHECK-NEXT: [[V1:%.*]] = add i32 [[V0_OFF]], [[ARG]]
-; CHECK-NEXT: [[V2:%.*]] = add i32 [[V1]], 0
; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { ptr addrspace(8), i32 } poison, ptr addrspace(8) [[V0_RSRC]], 0
-; CHECK-NEXT: [[TMP2:%.*]] = insertvalue { ptr addrspace(8), i32 } [[TMP1]], i32 [[V2]], 1
-; CHECK-NEXT: ret { ptr addrspace(8), i32 } [[TMP2]]
+; CHECK-NEXT: [[V2:%.*]] = insertvalue { ptr addrspace(8), i32 } [[TMP1]], i32 [[V1]], 1
+; CHECK-NEXT: ret { ptr addrspace(8), i32 } [[V2]]
;
%v1 = getelementptr i8, ptr addrspace(7) %v0, i32 %arg
%v2 = getelementptr i8, ptr addrspace(7) %v1, i32 0
@@ -124,8 +122,7 @@ define ptr addrspace(7) @zero_gep_goes_first(ptr addrspace(7) %v0, i32 %arg) {
; CHECK-SAME: ({ ptr addrspace(8), i32 } [[V0:%.*]], i32 [[ARG:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[V0_RSRC:%.*]] = extractvalue { ptr addrspace(8), i32 } [[V0]], 0
; CHECK-NEXT: [[V0_OFF:%.*]] = extractvalue { ptr addrspace(8), i32 } [[V0]], 1
-; CHECK-NEXT: [[V1:%.*]] = add i32 [[V0_OFF]], 0
-; CHECK-NEXT: [[V2:%.*]] = add i32 [[V1]], [[ARG]]
+; CHECK-NEXT: [[V2:%.*]] = add i32 [[V0_OFF]], [[ARG]]
; CHECK-NEXT: [[TMP1:%.*]] = insertvalue { ptr addrspace(8), i32 } poison, ptr addrspace(8) [[V0_RSRC]], 0
; CHECK-NEXT: [[TMP2:%.*]] = insertvalue { ptr addrspace(8), i32 } [[TMP1]], i32 [[V2]], 1
; CHECK-NEXT: ret { ptr addrspace(8), i32 } [[TMP2]]
More information about the llvm-commits
mailing list