[clang] b2bd024 - [CGExprAgg] Don't create zero index GEP
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 30 02:47:17 PDT 2024
Author: Nikita Popov
Date: 2024-05-30T11:47:07+02:00
New Revision: b2bd024384b484647da9fd9863bf6f77b5731949
URL: https://github.com/llvm/llvm-project/commit/b2bd024384b484647da9fd9863bf6f77b5731949
DIFF: https://github.com/llvm/llvm-project/commit/b2bd024384b484647da9fd9863bf6f77b5731949.diff
LOG: [CGExprAgg] Don't create zero index GEP
With opaque pointers, we no longer need a zero-index GEP to get
the first element.
Added:
Modified:
clang/lib/CodeGen/CGExprAgg.cpp
clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp
clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 7a92fc3dfb4a4..5b2039af6128b 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -448,11 +448,7 @@ AggExprEmitter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
AggValueSlot Dest = EnsureSlot(E->getType());
LValue DestLV = CGF.MakeAddrLValue(Dest.getAddress(), E->getType());
LValue Start = CGF.EmitLValueForFieldInitialization(DestLV, *Field);
- llvm::Value *Zero = llvm::ConstantInt::get(CGF.PtrDiffTy, 0);
- llvm::Value *IdxStart[] = { Zero, Zero };
- llvm::Value *ArrayStart = Builder.CreateInBoundsGEP(
- ArrayPtr.getElementType(), ArrayPtr.emitRawPointer(CGF), IdxStart,
- "arraystart");
+ llvm::Value *ArrayStart = ArrayPtr.emitRawPointer(CGF);
CGF.EmitStoreThroughLValue(RValue::get(ArrayStart), Start);
++Field;
@@ -467,6 +463,7 @@ AggExprEmitter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) {
Ctx.hasSameType(Field->getType()->getPointeeType(),
ArrayType->getElementType())) {
// End pointer.
+ llvm::Value *Zero = llvm::ConstantInt::get(CGF.PtrDiffTy, 0);
llvm::Value *IdxEnd[] = { Zero, Size };
llvm::Value *ArrayEnd = Builder.CreateInBoundsGEP(
ArrayPtr.getElementType(), ArrayPtr.emitRawPointer(CGF), IdxEnd,
diff --git a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp
index a95a458220b08..d9e4c5d5403c2 100644
--- a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp
+++ b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist-startend.cpp
@@ -49,7 +49,6 @@ void fn1(int i) {
// CHECK-NEXT: store
// init the list
// CHECK-NEXT: getelementptr
- // CHECK-NEXT: getelementptr inbounds [3 x i32], ptr
// CHECK-NEXT: store ptr
// CHECK-NEXT: getelementptr
// CHECK-NEXT: getelementptr inbounds [3 x i32], ptr [[array]], i{{32|64}} 0, i{{32|64}} 3
diff --git a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
index d97a9310cdcfa..aa2f078a5fb0c 100644
--- a/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
+++ b/clang/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
@@ -131,7 +131,6 @@ void fn1(int i) {
// CHECK-NEXT: store
// init the list
// CHECK-NEXT: getelementptr
- // CHECK-NEXT: getelementptr inbounds [3 x i32], ptr
// CHECK-NEXT: store ptr
// CHECK-NEXT: getelementptr
// CHECK-NEXT: store i{{32|64}} 3
More information about the cfe-commits
mailing list