[PATCH] Fix for PR 14779: PPC64: Assertion failure in CodeGen/MachineInstr.cpp

Kai kai at redstar.de
Wed Feb 13 22:54:44 PST 2013


Hi!

I updated the patch according to the comments from Bill:

The implementation now uses the same approach as the Mips and ARM 
implementation. I also fixed the Darwin argument lowering because it 
suffers from the same problem. The test now checks more variants.

Regards
Kai


On 11.02.2013 07:41, Kai wrote:
> Hi!
>
> The attached patch fixes PR 14779.
>
> The root problem here is that the function argument list and the Ins
> vector may not have the same length. E.g. this happens if an anonymous
> aggregate is passed by value. In such a case the variable FuncArg is not
> in sync with Ins[ArgNo] and results in an assertion failure.
>
> My patch moves the computation of FuncArg inside the block which handles
> byVal parameters. This guarantees that FuncArg refers to the same
> argument as Ins[ArgNo].
>
> Regards
> Kai
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>


-------------- next part --------------
diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp
index e789112..43eae93 100644
--- a/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -2162,13 +2162,16 @@ PPCTargetLowering::LowerFormalArguments_64SVR4(
   SmallVector<SDValue, 8> MemOps;
   unsigned nAltivecParamsAtEnd = 0;
   Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin();
-  for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo, ++FuncArg) {
+  unsigned CurArgIdx = 0;
+  for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
     SDValue ArgVal;
     bool needsLoad = false;
     EVT ObjectVT = Ins[ArgNo].VT;
     unsigned ObjSize = ObjectVT.getSizeInBits()/8;
     unsigned ArgSize = ObjSize;
     ISD::ArgFlagsTy Flags = Ins[ArgNo].Flags;
+    std::advance(FuncArg, Ins[ArgNo].OrigArgIndex - CurArgIdx);
+    CurArgIdx = Ins[ArgNo].OrigArgIndex;
 
     unsigned CurArgOffset = ArgOffset;
 
@@ -2504,13 +2507,16 @@ PPCTargetLowering::LowerFormalArguments_Darwin(
   SmallVector<SDValue, 8> MemOps;
   unsigned nAltivecParamsAtEnd = 0;
   Function::const_arg_iterator FuncArg = MF.getFunction()->arg_begin();
-  for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo, ++FuncArg) {
+  unsigned CurArgIdx = 0;
+  for (unsigned ArgNo = 0, e = Ins.size(); ArgNo != e; ++ArgNo) {
     SDValue ArgVal;
     bool needsLoad = false;
     EVT ObjectVT = Ins[ArgNo].VT;
     unsigned ObjSize = ObjectVT.getSizeInBits()/8;
     unsigned ArgSize = ObjSize;
     ISD::ArgFlagsTy Flags = Ins[ArgNo].Flags;
+    std::advance(FuncArg, Ins[ArgNo].OrigArgIndex - CurArgIdx);
+    CurArgIdx = Ins[ArgNo].OrigArgIndex;
 
     unsigned CurArgOffset = ArgOffset;
 
diff --git a/test/CodeGen/PowerPC/anon_aggr.ll b/test/CodeGen/PowerPC/anon_aggr.ll
new file mode 100644
index 0000000..d3ad90a
--- /dev/null
+++ b/test/CodeGen/PowerPC/anon_aggr.ll
@@ -0,0 +1,105 @@
+; RUN: llc -mtriple=powerpc64-unknown-linux-gnu < %s | FileCheck -check-prefix=LINUX %s
+; RUN: llc -mtriple=powerpc64-apple-darwin < %s | FileCheck -check-prefix=DARWIN %s
+
+; Test case for PR 14779: anonymous aggregates are not handled correctly.
+; The bug is triggered by passing a byval structure after an anonymous
+; aggregate.
+
+;target datalayout = "E-p:64:64:64-S0-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-n32:64"
+;target triple = "powerpc64-unknown-linux-gnu"
+
+%tarray = type { i64, i8* }
+
+define i8* @func1({ i64, i8* } %array, i8* %ptr) {
+entry:
+  %array_ptr = extractvalue {i64, i8* } %array, 1
+  %cond = icmp eq i8* %array_ptr, %ptr
+  br i1 %cond, label %equal, label %unequal
+equal:
+  ret i8* %array_ptr
+unequal:
+  ret i8* %ptr
+}
+
+; LINUX: cmpld 0, 4, 5
+; LINUX: mr 3, 5
+; LINUX: mr 3, 4
+; DARWIN: cmpld cr0, r4, r5
+; DARWIN: mr r3, r5
+; DARWIN: mr r3, r4
+
+
+define i8* @func2({ i64, i8* } %array1, %tarray* byval %array2) {
+entry:
+  %array1_ptr = extractvalue {i64, i8* } %array1, 1
+  %tmp = getelementptr inbounds %tarray* %array2, i32 0, i32 1
+  %array2_ptr = load i8** %tmp
+  %cond = icmp eq i8* %array1_ptr, %array2_ptr
+  br i1 %cond, label %equal, label %unequal
+equal:
+  ret i8* %array1_ptr
+unequal:
+  ret i8* %array2_ptr
+}
+
+; LINUX: addi 3, 1, 64
+; LINUX: ld 3, 8(3)
+; LINUX: cmpld 0, 4, 3
+; LINUX: mr 3, 4
+; DARWIN: addi r3, r1, 64
+; DARWIN: ld r3, 8(r3)
+; DARWIN: cmpld cr0, r4, r3
+; DARWIN: mr r3, r4
+
+define i8* @func3({ i64, i8* }* byval %array1, %tarray* byval %array2) {
+entry:
+  %tmp1 = getelementptr inbounds { i64, i8* }* %array1, i32 0, i32 1
+  %array1_ptr = load i8** %tmp1
+  %tmp2 = getelementptr inbounds %tarray* %array2, i32 0, i32 1
+  %array2_ptr = load i8** %tmp2
+  %cond = icmp eq i8* %array1_ptr, %array2_ptr
+  br i1 %cond, label %equal, label %unequal
+equal:
+  ret i8* %array1_ptr
+unequal:
+  ret i8* %array2_ptr
+}
+
+; LINUX: addi 3, 1, 64
+; LINUX: addi 5, 1, 48
+; LINUX: ld 3, 8(3)
+; LINUX: ld 4, 8(5)
+; LINUX: cmpld 0, 4, 3
+; LINUX: mr 3, 4
+; DARWIN: addi r3, r1, 64
+; DARWIN: addi r5, r1, 48
+; DARWIN: ld r3, 8(r3)
+; DARWIN: ld r4, 8(r5)
+; DARWIN: cmpld cr0, r4, r3
+; DARWIN: mr r3, r4
+
+define i8* @func4(i64 %p1, i64 %p2, i64 %p3, i64 %p4,
+                  i64 %p5, i64 %p6, i64 %p7, i64 %p8,
+                  { i64, i8* } %array1, %tarray* byval %array2) {
+entry:
+  %array1_ptr = extractvalue {i64, i8* } %array1, 1
+  %tmp = getelementptr inbounds %tarray* %array2, i32 0, i32 1
+  %array2_ptr = load i8** %tmp
+  %cond = icmp eq i8* %array1_ptr, %array2_ptr
+  br i1 %cond, label %equal, label %unequal
+equal:
+  ret i8* %array1_ptr
+unequal:
+  ret i8* %array2_ptr
+}
+
+; LINUX: addi 4, 1, 128
+; LINUX: ld 3, 120(1)
+; LINUX: ld 4, 8(4)
+; LINUX: cmpld 0, 3, 4
+; LINUX: mr 3, 4
+; DARWIN: addi r4, r1, 128
+; DARWIN: ld r3, 120(r1)
+; DARWIN: ld r4, 8(r4)
+; DARWIN: cmpld cr0, r3, r4
+; DARWIN: mr r3, r4



More information about the llvm-commits mailing list