Please find enclosed an updated patch containing a test showing the
difference in the generated IR.
Tom
On Mon, Jun 16, 2014 at 3:25 PM, Rafael Espíndola <
[email protected]> wrote:
> Can you write a test showing the difference is the generated IR? Look
> at the tests i clang/test/CodeGen for examples.
>
> On 16 June 2014 13:46, Thomas Jablin <[email protected]> wrote:
> > Hi,
> > Please find enclosed a patch to resolve PR20018. According to the x86-64
> > ABI, structures with both floating point and integer members are split
> > between floating-point and general purpose registers, and consecutive
> 32-bit
> > floats can be packed into a single floating point register. In variadic
> > functions, clang writes out the state of the GP registers and FP
> registers
> > to different regions in memory. A bug in the TargetInfo logic is causing
> > llvm to try to read floating point arguments from the FP region of the
> > stack. Specifically:
> >
> > 02593 llvm::Value *RegLoAddr = TyLo->isFloatingPointTy() ? FPAddr :
> > GPAddr;
> > 02594 llvm::Value *RegHiAddr = TyLo->isFloatingPointTy() ? GPAddr :
> > FPAddr;
> >
> > Are checking if TyLo is a floating point type, however, two consecutive
> > floating point fields will be represented as an floating point vector.
> > Consequently, the correct code should be:
> >
> > 02593 llvm::Value *RegLoAddr = TyLo->isFPOrFPVectorTy() ? FPAddr :
> > GPAddr;
> > 02594 llvm::Value *RegHiAddr = TyLo->isFPOrFPVectorTy() ? GPAddr :
> > FPAddr;
> >
> > The code on line 2623 is already checking for floating point vectors
> > appropriately. I have also attached a simple test case named gpfpTest.c.
> > Thanks.
> > Tom
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > [email protected]
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
>
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp (revision 207039)
+++ lib/CodeGen/TargetInfo.cpp (working copy)
@@ -2626,8 +2626,8 @@
llvm::Type *PTyHi = llvm::PointerType::getUnqual(TyHi);
llvm::Value *GPAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
llvm::Value *FPAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
- llvm::Value *RegLoAddr = TyLo->isFloatingPointTy() ? FPAddr : GPAddr;
- llvm::Value *RegHiAddr = TyLo->isFloatingPointTy() ? GPAddr : FPAddr;
+ llvm::Value *RegLoAddr = TyLo->isFPOrFPVectorTy() ? FPAddr : GPAddr;
+ llvm::Value *RegHiAddr = TyLo->isFPOrFPVectorTy() ? GPAddr : FPAddr;
llvm::Value *V =
CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegLoAddr, PTyLo));
CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
Index: test/CodeGen/variadic-gpfp-x86.c
===================================================================
--- test/CodeGen/variadic-gpfp-x86.c (revision 0)
+++ test/CodeGen/variadic-gpfp-x86.c (working copy)
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+struct Bar {
+ float f1;
+ float f2;
+ unsigned u;
+};
+
+void foo(int i, ...) {
+ __builtin_va_list ap;
+ struct Bar b = __builtin_va_arg(ap, struct Bar);
+// CHECK: [[FPOP:%.*]] = getelementptr inbounds %struct.__va_list_tag* {{.*}}, i32 0, i32 1
+// CHECK: [[FPO:%.*]] = load i32* [[FPOP]]
+// CHECK: [[FPVEC:%.*]] = getelementptr i8* {{.*}}, i32 [[FPO]]
+// CHECK: bitcast i8* [[FPVEC]] to <2 x float>*
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits