llvm.org GIT mirror llvm / b0e21d4
Revert "Revert r240762 "[X86] Cleanup X86WindowsTargetObjectFile::getSectionForConstant"" This reverts commit r240793 while fixing how we handle array constant pool entries. This fixes PR23966. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240811 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 5 years ago
2 changed file(s) with 41 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
130130 return HexString;
131131 }
132132
133
134133 static std::string scalarConstantToHexString(const Constant *C) {
135134 Type *Ty = C->getType();
136 APInt AI;
137135 if (isa(C)) {
138 AI = APInt(Ty->getPrimitiveSizeInBits(), /*val=*/0);
139 } else if (Ty->isFloatTy() || Ty->isDoubleTy()) {
140 const auto *CFP = cast(C);
141 AI = CFP->getValueAPF().bitcastToAPInt();
142 } else if (Ty->isIntegerTy()) {
143 const auto *CI = cast(C);
144 AI = CI->getValue();
136 return APIntToHexString(APInt::getNullValue(Ty->getPrimitiveSizeInBits()));
137 } else if (const auto *CFP = dyn_cast(C)) {
138 return APIntToHexString(CFP->getValueAPF().bitcastToAPInt());
139 } else if (const auto *CI = dyn_cast(C)) {
140 return APIntToHexString(CI->getValue());
145141 } else {
146 llvm_unreachable("unexpected constant pool element type!");
142 unsigned NumElements;
143 if (isa(Ty))
144 NumElements = Ty->getVectorNumElements();
145 else
146 NumElements = Ty->getArrayNumElements();
147 std::string HexString;
148 for (int I = NumElements - 1, E = -1; I != E; --I)
149 HexString += scalarConstantToHexString(C->getAggregateElement(I));
150 return HexString;
147151 }
148 return APIntToHexString(AI);
149152 }
150153
151154 MCSection *
152155 X86WindowsTargetObjectFile::getSectionForConstant(SectionKind Kind,
153156 const Constant *C) const {
154 if (Kind.isReadOnly()) {
155 if (C) {
156 Type *Ty = C->getType();
157 SmallString<32> COMDATSymName;
158 if (Ty->isFloatTy() || Ty->isDoubleTy()) {
159 COMDATSymName = "__real@";
160 COMDATSymName += scalarConstantToHexString(C);
161 } else if (const auto *VTy = dyn_cast(Ty)) {
162 uint64_t NumBits = VTy->getBitWidth();
163 if (NumBits == 128 || NumBits == 256) {
164 COMDATSymName = NumBits == 128 ? "__xmm@" : "__ymm@";
165 for (int I = VTy->getNumElements() - 1, E = -1; I != E; --I)
166 COMDATSymName +=
167 scalarConstantToHexString(C->getAggregateElement(I));
168 }
169 }
170 if (!COMDATSymName.empty()) {
171 unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
172 COFF::IMAGE_SCN_MEM_READ |
173 COFF::IMAGE_SCN_LNK_COMDAT;
174 return getContext().getCOFFSection(".rdata", Characteristics, Kind,
175 COMDATSymName,
176 COFF::IMAGE_COMDAT_SELECT_ANY);
177 }
178 }
157 if (Kind.isMergeableConst() && C) {
158 const unsigned Characteristics = COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
159 COFF::IMAGE_SCN_MEM_READ |
160 COFF::IMAGE_SCN_LNK_COMDAT;
161 std::string COMDATSymName;
162 if (Kind.isMergeableConst4() || Kind.isMergeableConst8())
163 COMDATSymName = "__real@" + scalarConstantToHexString(C);
164 else if (Kind.isMergeableConst16())
165 COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
166
167 if (!COMDATSymName.empty())
168 return getContext().getCOFFSection(".rdata", Characteristics, Kind,
169 COMDATSymName,
170 COFF::IMAGE_COMDAT_SELECT_ANY);
179171 }
180172
181173 return TargetLoweringObjectFile::getSectionForConstant(Kind, C);
6363 ; CHECK: movaps __xmm@00000000000000003f8000003f800000(%rip), %xmm0
6464 ; CHECK-NEXT: ret
6565 }
66
67 define float @pr23966(i32 %a) {
68 %tobool = icmp ne i32 %a, 0
69 %sel = select i1 %tobool, float -1.000000e+00, float 1.000000e+00
70 ret float %sel
71 }
72
73 ; CHECK: .globl __real@bf8000003f800000
74 ; CHECK-NEXT: .section .rdata,"dr",discard,__real@bf8000003f800000
75 ; CHECK-NEXT: .align 4
76 ; CHECK-NEXT: __real@bf8000003f800000:
77 ; CHECK-NEXT: .long 1065353216
78 ; CHECK-NEXT: .long 3212836864