[llvm] r213038 - CodeGen: Handle ConstantVector and undef in WinCOFF constant pools
David Majnemer
david.majnemer at gmail.com
Mon Jul 14 19:34:13 PDT 2014
Author: majnemer
Date: Mon Jul 14 21:34:12 2014
New Revision: 213038
URL: http://llvm.org/viewvc/llvm-project?rev=213038&view=rev
Log:
CodeGen: Handle ConstantVector and undef in WinCOFF constant pools
The constant pool entry code for WinCOFF assumed that vector constants
would be formed using ConstantDataVector, it did not expect to see a
ConstantVector. Furthermore, it did not expect undef as one of the
elements of the vector.
ConstantVectors should be handled like ConstantDataVectors, treat Undef
as zero.
Modified:
llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp
llvm/trunk/test/CodeGen/X86/win_cst_pool.ll
Modified: llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp?rev=213038&r1=213037&r2=213038&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetObjectFile.cpp Mon Jul 14 21:34:12 2014
@@ -109,7 +109,8 @@ const MCExpr *X86WindowsTargetObjectFile
getContext());
}
-static std::string APIntToHexString(const APInt &AI, unsigned Width) {
+static std::string APIntToHexString(const APInt &AI) {
+ unsigned Width = (AI.getBitWidth() / 8) * 2;
std::string HexString = utohexstr(AI.getLimitedValue(), /*LowerCase=*/true);
unsigned Size = HexString.size();
assert(Width >= Size && "hex string is too large!");
@@ -121,17 +122,19 @@ static std::string APIntToHexString(cons
static std::string scalarConstantToHexString(const Constant *C) {
Type *Ty = C->getType();
- if (Ty->isFloatTy()) {
+ APInt AI;
+ if (isa<UndefValue>(C)) {
+ AI = APInt(Ty->getPrimitiveSizeInBits(), /*val=*/0);
+ } else if (Ty->isFloatTy() || Ty->isDoubleTy()) {
const auto *CFP = cast<ConstantFP>(C);
- return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/8);
- } else if (Ty->isDoubleTy()) {
- const auto *CFP = cast<ConstantFP>(C);
- return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/16);
- } else if (const auto *ITy = dyn_cast<IntegerType>(Ty)) {
+ AI = CFP->getValueAPF().bitcastToAPInt();
+ } else if (Ty->isIntegerTy()) {
const auto *CI = cast<ConstantInt>(C);
- return APIntToHexString(CI->getValue(), (ITy->getBitWidth() / 8) * 2);
+ AI = CI->getValue();
+ } else {
+ llvm_unreachable("unexpected constant pool element type!");
}
- llvm_unreachable("unexpected constant pool element type!");
+ return APIntToHexString(AI);
}
const MCSection *
@@ -147,11 +150,16 @@ X86WindowsTargetObjectFile::getSectionFo
} else if (const auto *VTy = dyn_cast<VectorType>(Ty)) {
uint64_t NumBits = VTy->getBitWidth();
if (NumBits == 128 || NumBits == 256) {
- const auto *CDV = cast<ConstantDataVector>(C);
COMDATSymName = NumBits == 128 ? "__xmm@" : "__ymm@";
- for (int I = CDV->getNumElements() - 1, E = -1; I != E; --I)
- COMDATSymName +=
- scalarConstantToHexString(CDV->getElementAsConstant(I));
+ if (const auto *CDV = dyn_cast<ConstantDataVector>(C)) {
+ for (int I = CDV->getNumElements() - 1, E = -1; I != E; --I)
+ COMDATSymName +=
+ scalarConstantToHexString(CDV->getElementAsConstant(I));
+ } else {
+ const auto *CV = cast<ConstantVector>(C);
+ for (int I = CV->getNumOperands() - 1, E = -1; I != E; --I)
+ COMDATSymName += scalarConstantToHexString(CV->getOperand(I));
+ }
}
}
if (!COMDATSymName.empty()) {
Modified: llvm/trunk/test/CodeGen/X86/win_cst_pool.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/win_cst_pool.ll?rev=213038&r1=213037&r2=213038&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/win_cst_pool.ll (original)
+++ llvm/trunk/test/CodeGen/X86/win_cst_pool.ll Mon Jul 14 21:34:12 2014
@@ -47,3 +47,20 @@ define <8 x i16> @vec2() {
; CHECK: vec2:
; CHECK: movaps __xmm at 00000001000200030004000500060007(%rip), %xmm0
; CHECK-NEXT: ret
+
+
+define <4 x float> @undef1() {
+ ret <4 x float> <float 1.0, float 1.0, float undef, float undef>
+
+; CHECK: .globl __xmm at 00000000000000003f8000003f800000
+; CHECK-NEXT: .section .rdata,"rd",discard,__xmm at 00000000000000003f8000003f800000
+; CHECK-NEXT: .align 16
+; CHECK-NEXT: __xmm at 00000000000000003f8000003f800000:
+; CHECK-NEXT: .long 1065353216 # float 1
+; CHECK-NEXT: .long 1065353216 # float 1
+; CHECK-NEXT: .zero 4
+; CHECK-NEXT: .zero 4
+; CHECK: undef1:
+; CHECK: movaps __xmm at 00000000000000003f8000003f800000(%rip), %xmm0
+; CHECK-NEXT: ret
+}
More information about the llvm-commits
mailing list