aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCameron Zwarich <zwarich@apple.com>2011-03-16 22:20:18 +0000
committerCameron Zwarich <zwarich@apple.com>2011-03-16 22:20:18 +0000
commitebe8173941238cfbabadb1c63bca7fb7dcf2adbe (patch)
treee26ad4384575e2b10d06cd5476abbe4d91724ada /lib
parent7be4b7ed75d0e094d2cb1998a3d4a8d346b5d839 (diff)
downloadexternal_llvm-ebe8173941238cfbabadb1c63bca7fb7dcf2adbe.zip
external_llvm-ebe8173941238cfbabadb1c63bca7fb7dcf2adbe.tar.gz
external_llvm-ebe8173941238cfbabadb1c63bca7fb7dcf2adbe.tar.bz2
The x86-64 ABI says that a bool is only guaranteed to be sign-extended to a byte
rather than an int. Thankfully, this only causes LLVM to miss optimizations, not generate incorrect code. This just fixes the zext at the return. We still insert an i32 ZextAssert when reading a function's arguments, but it is followed by a truncate and another i8 ZextAssert so it is not optimized. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127766 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp7
-rw-r--r--lib/Target/X86/X86ISelLowering.cpp9
-rw-r--r--lib/Target/X86/X86ISelLowering.h3
3 files changed, 14 insertions, 5 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index aa7009a..5548318 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1128,12 +1128,9 @@ void SelectionDAGBuilder::visitRet(const ReturnInst &I) {
else if (F->paramHasAttr(0, Attribute::ZExt))
ExtendKind = ISD::ZERO_EXTEND;
- // FIXME: C calling convention requires the return type to be promoted
- // to at least 32-bit. But this is not necessary for non-C calling
- // conventions. The frontend should mark functions whose return values
- // require promoting with signext or zeroext attributes.
if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger()) {
- EVT MinVT = TLI.getRegisterType(*DAG.getContext(), MVT::i32);
+ MVT ReturnMVT = TLI.getTypeForExtendedInteger(VT, ExtendKind);
+ EVT MinVT = TLI.getRegisterType(*DAG.getContext(), ReturnMVT);
if (VT.bitsLT(MinVT))
VT = MinVT;
}
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 910ed2a..c1aa720 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -1448,6 +1448,15 @@ bool X86TargetLowering::isUsedByReturnOnly(SDNode *N) const {
return HasRet;
}
+MVT
+X86TargetLowering::getTypeForExtendedInteger(EVT VT,
+ ISD::NodeType ExtendKind) const {
+ // TODO: Is this also valid on 32-bit?
+ if (Subtarget->is64Bit() && VT == MVT::i1 && ExtendKind == ISD::ZERO_EXTEND)
+ return MVT::i8;
+ return MVT::i32;
+}
+
/// LowerCallResult - Lower the result values of a call into the
/// appropriate copies out of appropriate physical registers.
///
diff --git a/lib/Target/X86/X86ISelLowering.h b/lib/Target/X86/X86ISelLowering.h
index 551884b..0857c59 100644
--- a/lib/Target/X86/X86ISelLowering.h
+++ b/lib/Target/X86/X86ISelLowering.h
@@ -843,6 +843,9 @@ namespace llvm {
virtual bool isUsedByReturnOnly(SDNode *N) const;
+ virtual MVT
+ getTypeForExtendedInteger(EVT VT, ISD::NodeType ExtendKind) const;
+
virtual bool
CanLowerReturn(CallingConv::ID CallConv, bool isVarArg,
const SmallVectorImpl<ISD::OutputArg> &Outs,