[cfe-commits] r130717 - in /cfe/trunk: lib/CodeGen/CGCall.cpp lib/CodeGen/CGCall.h test/CodeGen/byval-memcpy-elim.c
Douglas Gregor
dgregor at apple.com
Sat May 7 13:17:31 PDT 2011
On May 2, 2011, at 1:24 PM, Eli Friedman wrote:
> Author: efriedma
> Date: Mon May 2 15:24:29 2011
> New Revision: 130717
>
> URL: http://llvm.org/viewvc/llvm-project?rev=130717&view=rev
> Log:
> Skip extra copy from aggregate where it isn't necessary; rdar://problem/8139919 . This shouldn't make much of a difference at -O3, but should substantially reduce the number of generated memcpy's at -O0.
This is causing us to get zeroed struct returns in some cases (<rdar://problem/9402621>). Here's a failing example:
#import <AppKit/AppKit.h>
@interface MyObject : NSObject
+ (NSRect)doubleRect:(NSRect)rect;
@end
@implementation MyObject
+ (NSRect)doubleRect:(NSRect)rect
{
NSLog(@"input rect is: %@", NSStringFromRect(rect));
return NSMakeRect(rect.origin.x * 2, rect.origin.y * 2, rect.size.width * 2, rect.size.height * 2);
}
@end
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRect rect = NSMakeRect(100, 200, 300, 400);
NSLog(@"rect is: %@", NSStringFromRect(rect));
rect = [MyObject doubleRect:rect];
NSLog(@"rect is now: %@", NSStringFromRect(rect));
[pool drain];
}
I've reverted this change in r131057.
- Doug
>
> Added:
> cfe/trunk/test/CodeGen/byval-memcpy-elim.c
> Modified:
> cfe/trunk/lib/CodeGen/CGCall.cpp
> cfe/trunk/lib/CodeGen/CGCall.h
>
> Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=130717&r1=130716&r2=130717&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon May 2 15:24:29 2011
> @@ -1166,6 +1166,15 @@
> return args.add(EmitReferenceBindingToExpr(E, /*InitializedDecl=*/0),
> type);
>
> + if (hasAggregateLLVMType(type) && isa<ImplicitCastExpr>(E) &&
> + cast<CastExpr>(E)->getCastKind() == CK_LValueToRValue) {
> + LValue L = EmitLValue(cast<CastExpr>(E)->getSubExpr());
> + assert(L.isSimple());
> + args.add(RValue::getAggregate(L.getAddress(), L.isVolatileQualified()),
> + type, /*NeedsCopy*/true);
> + return;
> + }
> +
> args.add(EmitAnyExprToTemp(E), type);
> }
>
> @@ -1231,6 +1240,10 @@
> Alignment, I->Ty);
> else
> StoreComplexToAddr(RV.getComplexVal(), Args.back(), false);
> + } else if (I->NeedsCopy && !ArgInfo.getIndirectByVal()) {
> + Args.push_back(CreateMemTemp(I->Ty));
> + EmitAggregateCopy(Args.back(), RV.getAggregateAddr(), I->Ty,
> + RV.isVolatileQualified());
> } else {
> Args.push_back(RV.getAggregateAddr());
> }
>
> Modified: cfe/trunk/lib/CodeGen/CGCall.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.h?rev=130717&r1=130716&r2=130717&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGCall.h (original)
> +++ cfe/trunk/lib/CodeGen/CGCall.h Mon May 2 15:24:29 2011
> @@ -47,8 +47,9 @@
> struct CallArg {
> RValue RV;
> QualType Ty;
> - CallArg(RValue rv, QualType ty)
> - : RV(rv), Ty(ty)
> + bool NeedsCopy;
> + CallArg(RValue rv, QualType ty, bool needscopy)
> + : RV(rv), Ty(ty), NeedsCopy(needscopy)
> { }
> };
>
> @@ -57,8 +58,8 @@
> class CallArgList :
> public llvm::SmallVector<CallArg, 16> {
> public:
> - void add(RValue rvalue, QualType type) {
> - push_back(CallArg(rvalue, type));
> + void add(RValue rvalue, QualType type, bool needscopy = false) {
> + push_back(CallArg(rvalue, type, needscopy));
> }
> };
>
>
> Added: cfe/trunk/test/CodeGen/byval-memcpy-elim.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/byval-memcpy-elim.c?rev=130717&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/byval-memcpy-elim.c (added)
> +++ cfe/trunk/test/CodeGen/byval-memcpy-elim.c Mon May 2 15:24:29 2011
> @@ -0,0 +1,20 @@
> +// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s
> +
> +struct Test1S {
> + long NumDecls;
> + long X;
> + long Y;
> +};
> +struct Test2S {
> + long NumDecls;
> + long X;
> +};
> +
> +// Make sure we don't generate extra memcpy for lvalues
> +void test1a(struct Test1S, struct Test2S);
> +// CHECK: define void @test1(
> +// CHECK-NOT: memcpy
> +// CHECK: call void @test1a
> +void test1(struct Test1S *A, struct Test2S *B) {
> + test1a(*A, *B);
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list