[llvm] r333747 - [AArch64][GlobalISel] Zero-extend s1 values when returning.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 1 06:20:32 PDT 2018
Author: aemerson
Date: Fri Jun 1 06:20:32 2018
New Revision: 333747
URL: http://llvm.org/viewvc/llvm-project?rev=333747&view=rev
Log:
[AArch64][GlobalISel] Zero-extend s1 values when returning.
Before we were relying on the any extend of the s1 to s32, but
for AAPCS we need to zero-extend it to at least s8.
Fixes PR36719
Differential Revision: https://reviews.llvm.org/D47425
Modified:
llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/trunk/lib/Target/AArch64/AArch64CallLowering.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp?rev=333747&r1=333746&r2=333747&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp Fri Jun 1 06:20:32 2018
@@ -726,17 +726,7 @@ LegalizerHelper::widenScalar(MachineInst
WideTy != LLT::scalar(8))
return UnableToLegalize;
- const auto &TLI = *MIRBuilder.getMF().getSubtarget().getTargetLowering();
- switch (TLI.getBooleanContents(false, false)) {
- case TargetLoweringBase::ZeroOrNegativeOneBooleanContent:
- widenScalarSrc(MI, WideTy, 0, TargetOpcode::G_SEXT);
- break;
- case TargetLoweringBase::ZeroOrOneBooleanContent:
- widenScalarSrc(MI, WideTy, 0, TargetOpcode::G_ZEXT);
- break;
- default:
- widenScalarSrc(MI, WideTy, 0, TargetOpcode::G_ANYEXT);
- }
+ widenScalarSrc(MI, WideTy, 0, TargetOpcode::G_ZEXT);
MIRBuilder.recordInsertion(&MI);
return Legalized;
}
Modified: llvm/trunk/lib/Target/AArch64/AArch64CallLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64CallLowering.cpp?rev=333747&r1=333746&r2=333747&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64CallLowering.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64CallLowering.cpp Fri Jun 1 06:20:32 2018
@@ -229,9 +229,14 @@ bool AArch64CallLowering::lowerReturn(Ma
assert(((Val && VReg) || (!Val && !VReg)) && "Return value without a vreg");
bool Success = true;
if (VReg) {
+ MachineRegisterInfo &MRI = MF.getRegInfo();
+
+ // We zero-extend i1s to i8.
+ if (MRI.getType(VReg).getSizeInBits() == 1)
+ VReg = MIRBuilder.buildZExt(LLT::scalar(8), VReg)->getOperand(0).getReg();
+
const AArch64TargetLowering &TLI = *getTLI<AArch64TargetLowering>();
CCAssignFn *AssignFn = TLI.CCAssignFnForReturn(F.getCallingConv());
- MachineRegisterInfo &MRI = MF.getRegInfo();
auto &DL = F.getParent()->getDataLayout();
ArgInfo OrigArg{VReg, Val->getType()};
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll?rev=333747&r1=333746&r2=333747&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll Fri Jun 1 06:20:32 2018
@@ -1859,3 +1859,14 @@ define void @test_nested_aggregate_const
store %agg.nested { i32 1, i32 1, %agg.inner { i16 2, i8 3, %agg.inner.inner {i64 5, i64 8} }, i32 13}, %agg.nested *%ptr
ret void
}
+
+define i1 @return_i1_zext() {
+; AAPCS ABI says that booleans can only be 1 or 0, so we need to zero-extend.
+; CHECK-LABEL: name: return_i1_zext
+; CHECK: [[CST:%[0-9]+]]:_(s1) = G_CONSTANT i1 true
+; CHECK: [[ZEXT:%[0-9]+]]:_(s8) = G_ZEXT [[CST]](s1)
+; CHECK: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[ZEXT]](s8)
+; CHECK: $w0 = COPY [[ANYEXT]](s32)
+; CHECK: RET_ReallyLR implicit $w0
+ ret i1 true
+}
More information about the llvm-commits
mailing list