[llvm] d1c0092 - SeparateConstOffsetFromGEP: Fix creating pointless bitcasts
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 27 18:08:00 PST 2022
Author: Matt Arsenault
Date: 2022-11-27T20:53:48-05:00
New Revision: d1c0092163d277103f1551d4b76b676cad511f44
URL: https://github.com/llvm/llvm-project/commit/d1c0092163d277103f1551d4b76b676cad511f44
DIFF: https://github.com/llvm/llvm-project/commit/d1c0092163d277103f1551d4b76b676cad511f44.diff
LOG: SeparateConstOffsetFromGEP: Fix creating pointless bitcasts
This was directly creating new BitCastInsts, so under opaque pointers,
would end up producing bitcast from ptr to ptr.
Added:
Modified:
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/split-gep.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index 7da5a78772ade..a5d6416756493 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -1122,18 +1122,17 @@ bool SeparateConstOffsetFromGEP::splitGEP(GetElementPtrInst *GEP) {
// sizeof(int64).
//
// Emit an uglygep in this case.
- Type *I8PtrTy = Type::getInt8PtrTy(GEP->getContext(),
- GEP->getPointerAddressSpace());
- NewGEP = new BitCastInst(NewGEP, I8PtrTy, "", GEP);
- NewGEP = GetElementPtrInst::Create(
- Type::getInt8Ty(GEP->getContext()), NewGEP,
- ConstantInt::get(IntPtrTy, AccumulativeByteOffset, true), "uglygep",
- GEP);
+ IRBuilder<> Builder(GEP);
+ Type *I8PtrTy =
+ Builder.getInt8Ty()->getPointerTo(GEP->getPointerAddressSpace());
+
+ NewGEP = cast<Instruction>(Builder.CreateGEP(
+ Builder.getInt8Ty(), Builder.CreateBitCast(NewGEP, I8PtrTy),
+ {ConstantInt::get(IntPtrTy, AccumulativeByteOffset, true)}, "uglygep",
+ GEPWasInBounds));
+
NewGEP->copyMetadata(*GEP);
- // Inherit the inbounds attribute of the original GEP.
- cast<GetElementPtrInst>(NewGEP)->setIsInBounds(GEPWasInBounds);
- if (GEP->getType() != I8PtrTy)
- NewGEP = new BitCastInst(NewGEP, GEP->getType(), GEP->getName(), GEP);
+ NewGEP = cast<Instruction>(Builder.CreateBitCast(NewGEP, GEP->getType()));
}
GEP->replaceAllUsesWith(NewGEP);
diff --git a/llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/split-gep.ll b/llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/split-gep.ll
index 743e1c2c80e93..60d005be3d73e 100644
--- a/llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/split-gep.ll
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/AMDGPU/split-gep.ll
@@ -15,8 +15,7 @@ define ptr addrspace(3) @packed_struct(i32 %i, i32 %j) {
; CHECK-NEXT: [[TMP0:%.*]] = sext i32 [[I:%.*]] to i64
; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[J:%.*]] to i64
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr [1024 x %struct.Packed], ptr addrspace(3) @packed_struct_array, i64 0, i64 [[TMP0]], i32 1, i64 [[TMP1]]
-; CHECK-NEXT: [[TMP3:%.*]] = bitcast ptr addrspace(3) [[TMP2]] to ptr addrspace(3)
-; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[TMP3]], i64 100
+; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[TMP2]], i64 100
; CHECK-NEXT: ret ptr addrspace(3) [[UGLYGEP]]
;
entry:
More information about the llvm-commits
mailing list