llvm.org GIT mirror llvm / cdc1044
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213038 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 6 years ago
2 changed file(s) with 38 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
108108 getContext());
109109 }
110110
111 static std::string APIntToHexString(const APInt &AI, unsigned Width) {
111 static std::string APIntToHexString(const APInt &AI) {
112 unsigned Width = (AI.getBitWidth() / 8) * 2;
112113 std::string HexString = utohexstr(AI.getLimitedValue(), /*LowerCase=*/true);
113114 unsigned Size = HexString.size();
114115 assert(Width >= Size && "hex string is too large!");
120121
121122 static std::string scalarConstantToHexString(const Constant *C) {
122123 Type *Ty = C->getType();
123 if (Ty->isFloatTy()) {
124 APInt AI;
125 if (isa(C)) {
126 AI = APInt(Ty->getPrimitiveSizeInBits(), /*val=*/0);
127 } else if (Ty->isFloatTy() || Ty->isDoubleTy()) {
124128 const auto *CFP = cast(C);
125 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/8);
126 } else if (Ty->isDoubleTy()) {
127 const auto *CFP = cast(C);
128 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt(), /*Width=*/16);
129 } else if (const auto *ITy = dyn_cast(Ty)) {
129 AI = CFP->getValueAPF().bitcastToAPInt();
130 } else if (Ty->isIntegerTy()) {
130131 const auto *CI = cast(C);
131 return APIntToHexString(CI->getValue(), (ITy->getBitWidth() / 8) * 2);
132 AI = CI->getValue();
133 } else {
134 llvm_unreachable("unexpected constant pool element type!");
132135 }
133 llvm_unreachable("unexpected constant pool element type!");
136 return APIntToHexString(AI);
134137 }
135138
136139 const MCSection *
146149 } else if (const auto *VTy = dyn_cast(Ty)) {
147150 uint64_t NumBits = VTy->getBitWidth();
148151 if (NumBits == 128 || NumBits == 256) {
149 const auto *CDV = cast(C);
150152 COMDATSymName = NumBits == 128 ? "__xmm@" : "__ymm@";
151 for (int I = CDV->getNumElements() - 1, E = -1; I != E; --I)
152 COMDATSymName +=
153 scalarConstantToHexString(CDV->getElementAsConstant(I));
153 if (const auto *CDV = dyn_cast(C)) {
154 for (int I = CDV->getNumElements() - 1, E = -1; I != E; --I)
155 COMDATSymName +=
156 scalarConstantToHexString(CDV->getElementAsConstant(I));
157 } else {
158 const auto *CV = cast(C);
159 for (int I = CV->getNumOperands() - 1, E = -1; I != E; --I)
160 COMDATSymName += scalarConstantToHexString(CV->getOperand(I));
161 }
154162 }
155163 }
156164 if (!COMDATSymName.empty()) {
4646 ; CHECK: vec2:
4747 ; CHECK: movaps __xmm@00000001000200030004000500060007(%rip), %xmm0
4848 ; CHECK-NEXT: ret
49
50
51 define <4 x float> @undef1() {
52 ret <4 x float>
53
54 ; CHECK: .globl __xmm@00000000000000003f8000003f800000
55 ; CHECK-NEXT: .section .rdata,"rd",discard,__xmm@00000000000000003f8000003f800000
56 ; CHECK-NEXT: .align 16
57 ; CHECK-NEXT: __xmm@00000000000000003f8000003f800000:
58 ; CHECK-NEXT: .long 1065353216 # float 1
59 ; CHECK-NEXT: .long 1065353216 # float 1
60 ; CHECK-NEXT: .zero 4
61 ; CHECK-NEXT: .zero 4
62 ; CHECK: undef1:
63 ; CHECK: movaps __xmm@00000000000000003f8000003f800000(%rip), %xmm0
64 ; CHECK-NEXT: ret
65 }