[llvm] r183568 - R600: Fix calculation of stack offset in AMDGPUFrameLowering
Tom Stellard
thomas.stellard at amd.com
Fri Jun 7 13:52:05 PDT 2013
Author: tstellar
Date: Fri Jun 7 15:52:05 2013
New Revision: 183568
URL: http://llvm.org/viewvc/llvm-project?rev=183568&view=rev
Log:
R600: Fix calculation of stack offset in AMDGPUFrameLowering
We weren't computing structure size correctly and we were relying on
the original alloca instruction to compute the offset, which isn't
always reliable.
Reviewed-by: Vincent Lejeune <vljn at ovi.com>
Modified:
llvm/trunk/lib/Target/R600/AMDGPUFrameLowering.cpp
llvm/trunk/test/CodeGen/R600/indirect-addressing.ll
Modified: llvm/trunk/lib/Target/R600/AMDGPUFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/AMDGPUFrameLowering.cpp?rev=183568&r1=183567&r2=183568&view=diff
==============================================================================
--- llvm/trunk/lib/Target/R600/AMDGPUFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/R600/AMDGPUFrameLowering.cpp Fri Jun 7 15:52:05 2013
@@ -78,27 +78,8 @@ int AMDGPUFrameLowering::getFrameIndexOf
int UpperBound = FI == -1 ? MFI->getNumObjects() : FI;
for (int i = MFI->getObjectIndexBegin(); i < UpperBound; ++i) {
- const AllocaInst *Alloca = MFI->getObjectAllocation(i);
- unsigned ArrayElements;
- const Type *AllocaType = Alloca->getAllocatedType();
- const Type *ElementType;
-
- if (AllocaType->isArrayTy()) {
- ArrayElements = AllocaType->getArrayNumElements();
- ElementType = AllocaType->getArrayElementType();
- } else {
- ArrayElements = 1;
- ElementType = AllocaType;
- }
-
- unsigned VectorElements;
- if (ElementType->isVectorTy()) {
- VectorElements = ElementType->getVectorNumElements();
- } else {
- VectorElements = 1;
- }
-
- Offset += (VectorElements / getStackWidth(MF)) * ArrayElements;
+ unsigned Size = MFI->getObjectSize(i);
+ Offset += (Size / (getStackWidth(MF) * 4));
}
return Offset;
}
Modified: llvm/trunk/test/CodeGen/R600/indirect-addressing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/R600/indirect-addressing.ll?rev=183568&r1=183567&r2=183568&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/R600/indirect-addressing.ll (original)
+++ llvm/trunk/test/CodeGen/R600/indirect-addressing.ll Fri Jun 7 15:52:05 2013
@@ -30,3 +30,36 @@ entry:
store i32 %3, i32 addrspace(1)* %arrayidx13
ret void
}
+
+; This test checks that the stack offset is calculated correctly for structs.
+; All register loads/stores should be optimized away, so there shouldn't be
+; any MOVA instructions.
+;
+; XXX: This generated code has unnecessary MOVs, we should be able to optimize
+; this.
+
+; CHECK: @multiple_structs
+; CHECK-NOT: MOVA_INT
+
+%struct.point = type { i32, i32 }
+
+define void @multiple_structs(i32 addrspace(1)* %out) {
+entry:
+ %a = alloca %struct.point
+ %b = alloca %struct.point
+ %a.x.ptr = getelementptr %struct.point* %a, i32 0, i32 0
+ %a.y.ptr = getelementptr %struct.point* %a, i32 0, i32 1
+ %b.x.ptr = getelementptr %struct.point* %b, i32 0, i32 0
+ %b.y.ptr = getelementptr %struct.point* %b, i32 0, i32 1
+ store i32 0, i32* %a.x.ptr
+ store i32 1, i32* %a.y.ptr
+ store i32 2, i32* %b.x.ptr
+ store i32 3, i32* %b.y.ptr
+ %a.indirect.ptr = getelementptr %struct.point* %a, i32 0, i32 0
+ %b.indirect.ptr = getelementptr %struct.point* %b, i32 0, i32 0
+ %a.indirect = load i32* %a.indirect.ptr
+ %b.indirect = load i32* %b.indirect.ptr
+ %0 = add i32 %a.indirect, %b.indirect
+ store i32 %0, i32 addrspace(1)* %out
+ ret void
+}
More information about the llvm-commits
mailing list