llvm.org GIT mirror llvm / 94107ba
- Avoid using floating point stores to implement memset unless the value is zero. - Do not try to infer GV alignment unless its type is sized. It's not possible to infer alignment if it has opaque type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100118 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 9 years ago
7 changed file(s) with 32 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
637637 /// determining it.
638638 virtual EVT getOptimalMemOpType(uint64_t Size,
639639 unsigned DstAlign, unsigned SrcAlign,
640 SelectionDAG &DAG) const {
640 bool SafeToUseFP, SelectionDAG &DAG) const {
641641 return MVT::Other;
642642 }
643643
31943194 /// is below the threshold. It returns the types of the sequence of
31953195 /// memory ops to perform memset / memcpy by reference.
31963196 static bool FindOptimalMemOpLowering(std::vector &MemOps,
3197 SDValue Dst, SDValue Src,
31983197 unsigned Limit, uint64_t Size,
31993198 unsigned DstAlign, unsigned SrcAlign,
3199 bool SafeToUseFP,
32003200 SelectionDAG &DAG,
32013201 const TargetLowering &TLI) {
32023202 assert((SrcAlign == 0 || SrcAlign >= DstAlign) &&
32063206 // the inferred alignment of the source. 'DstAlign', on the other hand, is the
32073207 // specified alignment of the memory operation. If it is zero, that means
32083208 // it's possible to change the alignment of the destination.
3209 EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign, DAG);
3209 EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign, SafeToUseFP, DAG);
32103210
32113211 if (VT == MVT::Other) {
32123212 VT = TLI.getPointerTy();
32843284 std::string Str;
32853285 bool CopyFromStr = isMemSrcFromString(Src, Str);
32863286 bool isZeroStr = CopyFromStr && Str.empty();
3287 if (!FindOptimalMemOpLowering(MemOps, Dst, Src, Limit, Size,
3287 if (!FindOptimalMemOpLowering(MemOps, Limit, Size,
32883288 (DstAlignCanChange ? 0 : Align),
3289 (isZeroStr ? 0 : SrcAlign), DAG, TLI))
3289 (isZeroStr ? 0 : SrcAlign), true, DAG, TLI))
32903290 return SDValue();
32913291
32923292 if (DstAlignCanChange) {
33683368 if (Align > SrcAlign)
33693369 SrcAlign = Align;
33703370
3371 if (!FindOptimalMemOpLowering(MemOps, Dst, Src, Limit, Size,
3371 if (!FindOptimalMemOpLowering(MemOps, Limit, Size,
33723372 (DstAlignCanChange ? 0 : Align),
3373 SrcAlign, DAG, TLI))
3373 SrcAlign, true, DAG, TLI))
33743374 return SDValue();
33753375
33763376 if (DstAlignCanChange) {
34353435 FrameIndexSDNode *FI = dyn_cast(Dst);
34363436 if (FI && !MFI->isFixedObjectIndex(FI->getIndex()))
34373437 DstAlignCanChange = true;
3438 if (!FindOptimalMemOpLowering(MemOps, Dst, Src, TLI.getMaxStoresPerMemset(),
3438 bool IsZero = isa(Src) &&
3439 cast(Src)->isNullValue();
3440 if (!FindOptimalMemOpLowering(MemOps, TLI.getMaxStoresPerMemset(),
34393441 Size, (DstAlignCanChange ? 0 : Align), 0,
3440 DAG, TLI))
3442 IsZero, DAG, TLI))
34413443 return SDValue();
34423444
34433445 if (DstAlignCanChange) {
61496151 unsigned Align = GV->getAlignment();
61506152 if (!Align) {
61516153 if (GlobalVariable *GVar = dyn_cast(GV)) {
6152 const TargetData *TD = TLI.getTargetData();
6153 Align = TD->getPreferredAlignment(GVar);
6154 if (GV->getType()->getElementType()->isSized()) {
6155 const TargetData *TD = TLI.getTargetData();
6156 Align = TD->getPreferredAlignment(GVar);
6157 }
61546158 }
61556159 }
61566160 return MinAlign(Align, GVOffset);
55405540
55415541 EVT PPCTargetLowering::getOptimalMemOpType(uint64_t Size,
55425542 unsigned DstAlign, unsigned SrcAlign,
5543 bool SafeToUseFP,
55435544 SelectionDAG &DAG) const {
55445545 if (this->PPCSubTarget.isPPC64()) {
55455546 return MVT::i64;
348348
349349 virtual EVT getOptimalMemOpType(uint64_t Size,
350350 unsigned DstAlign, unsigned SrcAlign,
351 SelectionDAG &DAG) const;
351 bool SafeToUseFP, SelectionDAG &DAG) const;
352352
353353 /// getFunctionAlignment - Return the Log2 alignment of this function.
354354 virtual unsigned getFunctionAlignment(const Function *F) const;
10751075 EVT
10761076 X86TargetLowering::getOptimalMemOpType(uint64_t Size,
10771077 unsigned DstAlign, unsigned SrcAlign,
1078 bool SafeToUseFP,
10781079 SelectionDAG &DAG) const {
10791080 // FIXME: This turns off use of xmm stores for memset/memcpy on targets like
10801081 // linux. This is because the stack realignment code can't handle certain
10881089 Subtarget->getStackAlignment() >= 16) {
10891090 if (Subtarget->hasSSE2())
10901091 return MVT::v4i32;
1091 if (Subtarget->hasSSE1())
1092 if (SafeToUseFP && Subtarget->hasSSE1())
10921093 return MVT::v4f32;
1093 } else if (Size >= 8 &&
1094 } else if (SafeToUseFP &&
1095 Size >= 8 &&
10941096 Subtarget->getStackAlignment() >= 8 &&
10951097 Subtarget->hasSSE2())
10961098 return MVT::f64;
424424 /// determining it.
425425 virtual EVT getOptimalMemOpType(uint64_t Size,
426426 unsigned DstAlign, unsigned SrcAlign,
427 SelectionDAG &DAG) const;
427 bool SafeToUseFP, SelectionDAG &DAG) const;
428428
429429 /// allowsUnalignedMemoryAccesses - Returns true if the target allows
430430 /// unaligned memory accesses. of the specified type.
33
44 declare void @llvm.memset.i32(i8*, i8, i32, i32) nounwind
55
6 define fastcc void @t() nounwind {
6 define fastcc void @t1() nounwind {
77 entry:
8 ; CHECK: t:
8 ; CHECK: t1:
99 ; CHECK: call memset
1010 call void @llvm.memset.i32( i8* null, i8 0, i32 188, i32 1 ) nounwind
1111 unreachable
1212 }
13
14 define fastcc void @t2(i8 signext %c) nounwind {
15 entry:
16 ; CHECK: t2:
17 ; CHECK: call memset
18 call void @llvm.memset.i32( i8* undef, i8 %c, i32 76, i32 1 ) nounwind
19 unreachable
20 }