CCAssignToStack<8,8>>
]>;
-def CC_Hexagon: CallingConv<[
+def CC_Hexagon_Legacy: CallingConv<[
CCIfType<[i1,i8,i16],
CCPromoteToType<i32>>,
CCIfType<[f32],
CCDelegateTo<CC_HexagonStack>
]>;
+def CC_Hexagon: CallingConv<[
+ CCIfType<[i1,i8,i16],
+ CCPromoteToType<i32>>,
+ CCIfType<[f32],
+ CCBitConvertToType<i32>>,
+ CCIfType<[f64],
+ CCBitConvertToType<i64>>,
+
+ CCIfByVal<
+ CCPassByVal<8,1>>,
+ CCIfArgIsVarArg<
+ CCDelegateTo<CC_HexagonStack>>,
+
+ // Pass split values in pairs, allocate odd register if necessary.
+ CCIfType<[i32],
+ CCIfSplit<
+ CCCustom<"CC_SkipOdd">>>,
+
+ CCIfType<[i32,v2i16,v4i8],
+ CCAssignToReg<[R0,R1,R2,R3,R4,R5]>>,
+ // Make sure to allocate any skipped 32-bit register, so it does not get
+ // allocated to a subsequent 32-bit value.
+ CCIfType<[i64,v2i32,v4i16,v8i8],
+ CCCustom<"CC_SkipOdd">>,
+ CCIfType<[i64,v2i32,v4i16,v8i8],
+ CCAssignToReg<[D0,D1,D2]>>,
+
+ CCDelegateTo<CC_HexagonStack>
+]>;
+
def RetCC_Hexagon: CallingConv<[
CCIfType<[i1,i8,i16],
CCPromoteToType<i32>>,
cl::Hidden, cl::init(false),
cl::desc("Rewrite unaligned loads as a pair of aligned loads"));
+static cl::opt<bool>
+ DisableArgsMinAlignment("hexagon-disable-args-min-alignment", cl::Hidden,
+ cl::init(false),
+ cl::desc("Disable minimum alignment of 1 for "
+ "arguments passed by value on stack"));
namespace {
if (Subtarget.useHVXOps())
CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_HVX);
+ else if (DisableArgsMinAlignment)
+ CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon_Legacy);
else
CCInfo.AnalyzeCallOperands(Outs, CC_Hexagon);
if (Subtarget.useHVXOps())
CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_HVX);
+ else if (DisableArgsMinAlignment)
+ CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon_Legacy);
else
CCInfo.AnalyzeFormalArguments(Ins, CC_Hexagon);
--- /dev/null
+; RUN: llc -march=hexagon -mcpu=hexagonv65 < %s | FileCheck %s
+; REQUIRES: hexagon
+
+; C file was:
+; struct S { char b; long long a; };
+; void foo(int x, struct S arg1);
+; void bar() {
+; struct S s;
+; s.b = 'a';
+; foo(42, s);
+;}
+
+;
+; Test that while passing a 7-byte struct on the stack, the
+; size of the struct is 16 bytes including padding since its
+; largest member is of type long long. This was being handled
+; correctly but is a sanity check against any potential future
+; regressions.
+;
+
+; CHECK: memd(r{{[0-9]+}}+#8) =
+; CHECK: memd(r{{[0-9]+}}+#0) =
+
+%struct.S = type { i8, i64 }
+
+; Function Attrs: nounwind
+define dso_local void @bar() local_unnamed_addr #0 {
+entry:
+ %s = alloca %struct.S, align 8
+ %0 = getelementptr inbounds %struct.S, %struct.S* %s, i32 0, i32 0
+ call void @llvm.lifetime.start.p0i8(i64 16, i8* nonnull %0) #3
+ store i8 97, i8* %0, align 8
+ tail call void @foo(i32 42, %struct.S* nonnull byval(%struct.S) align 8 %s) #3
+ call void @llvm.lifetime.end.p0i8(i64 16, i8* nonnull %0) #3
+ ret void
+}
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
+
+declare dso_local void @foo(i32, %struct.S* byval(%struct.S) align 8) local_unnamed_addr #2
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
+
--- /dev/null
+; RUN: llc -march=hexagon -mcpu=hexagonv65 < %s | FileCheck %s
+; REQUIRES: hexagon
+
+; C file was:
+; struct S { int a[3];};
+; void foo(int x, struct S arg1, struct S arg2);
+; void bar() {
+; struct S s;
+; s.a[0] = 9;
+; foo(42, s, s);
+; }
+
+; Test that while passing a 12-byte struct on the stack, the
+; struct is aligned to 4 bytes since its largest member is of type int.
+; Previously, the struct was being aligned to 8 bytes
+
+; CHECK: memw(r{{[0-9]+}}+#12) = #9
+
+; Check that the flag hexagon-disable-args-min-alignment works and the struct
+; is aligned to 8 bytes.
+; RUN: llc -march=hexagon -mcpu=hexagonv65 -hexagon-disable-args-min-alignment < %s | FileCheck -check-prefix=HEXAGON_LEGACY %s
+
+; HEXAGON_LEGACY: memw(r{{[0-9]+}}+#16) = #9
+
+%struct.S = type { [3 x i32] }
+
+; Function Attrs: nounwind
+define dso_local void @bar() local_unnamed_addr #0 {
+entry:
+ %s = alloca %struct.S, align 4
+ %0 = bitcast %struct.S* %s to i8*
+ call void @llvm.lifetime.start.p0i8(i64 12, i8* nonnull %0) #3
+ %arrayidx = getelementptr inbounds %struct.S, %struct.S* %s, i32 0, i32 0, i32 0
+ store i32 9, i32* %arrayidx, align 4
+ tail call void @foo(i32 42, %struct.S* nonnull byval(%struct.S) align 4 %s, %struct.S* nonnull byval(%struct.S) align 4 %s) #3
+ call void @llvm.lifetime.end.p0i8(i64 12, i8* nonnull %0) #3
+ ret void
+}
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
+
+declare dso_local void @foo(i32, %struct.S* byval(%struct.S) align 4, %struct.S* byval(%struct.S) align 4) local_unnamed_addr #2
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1