llvm.org GIT mirror llvm / 95d594c
Teach CodeGen's version of computeMaskedBits to understand the range metadata. This is the CodeGen equivalent of r153747. I tested that there is not noticeable performance difference with any combination of -O0/-O2 /-g when compiling gcc as a single compilation unit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153817 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 8 years ago
11 changed file(s) with 54 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
2323 class APInt;
2424 class TargetData;
2525 class StringRef;
26
26 class MDNode;
27
2728 /// ComputeMaskedBits - Determine which of the bits specified in Mask are
2829 /// known to be either zero or one and return them in the KnownZero/KnownOne
2930 /// bit sets. This code only analyzes bits in Mask, in order to short-circuit
3738 void ComputeMaskedBits(Value *V, const APInt &Mask, APInt &KnownZero,
3839 APInt &KnownOne, const TargetData *TD = 0,
3940 unsigned Depth = 0);
40
41 void computeMaskedBitsLoad(const MDNode &Ranges, const APInt &Mask,
42 APInt &KnownZero);
43
4144 /// ComputeSignBit - Determine whether the sign bit is known to be zero or
4245 /// one. Convenience wrapper around ComputeMaskedBits.
4346 void ComputeSignBit(Value *V, bool &KnownZero, bool &KnownOne,
379379 MachineMemOperand *getMachineMemOperand(MachinePointerInfo PtrInfo,
380380 unsigned f, uint64_t s,
381381 unsigned base_alignment,
382 const MDNode *TBAAInfo = 0);
382 const MDNode *TBAAInfo = 0,
383 const MDNode *Ranges = 0);
383384
384385 /// getMachineMemOperand - Allocate a new MachineMemOperand by copying
385386 /// an existing one, adjusting by an offset and using the given size.
8383 uint64_t Size;
8484 unsigned Flags;
8585 const MDNode *TBAAInfo;
86 const MDNode *Ranges;
8687
8788 public:
8889 /// Flags values. These may be or'd together.
104105 /// MachineMemOperand - Construct an MachineMemOperand object with the
105106 /// specified PtrInfo, flags, size, and base alignment.
106107 MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s,
107 unsigned base_alignment, const MDNode *TBAAInfo = 0);
108 unsigned base_alignment, const MDNode *TBAAInfo = 0,
109 const MDNode *Ranges = 0);
108110
109111 const MachinePointerInfo &getPointerInfo() const { return PtrInfo; }
110112
139141 /// getTBAAInfo - Return the TBAA tag for the memory reference.
140142 const MDNode *getTBAAInfo() const { return TBAAInfo; }
141143
144 /// getRanges - Return the range tag for the memory reference.
145 const MDNode *getRanges() const { return Ranges; }
146
142147 bool isLoad() const { return Flags & MOLoad; }
143148 bool isStore() const { return Flags & MOStore; }
144149 bool isVolatile() const { return Flags & MOVolatile; }
653653 SDValue getLoad(EVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr,
654654 MachinePointerInfo PtrInfo, bool isVolatile,
655655 bool isNonTemporal, bool isInvariant, unsigned Alignment,
656 const MDNode *TBAAInfo = 0);
656 const MDNode *TBAAInfo = 0, const MDNode *Ranges = 0);
657657 SDValue getExtLoad(ISD::LoadExtType ExtType, DebugLoc dl, EVT VT,
658658 SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo,
659659 EVT MemVT, bool isVolatile,
666666 SDValue Chain, SDValue Ptr, SDValue Offset,
667667 MachinePointerInfo PtrInfo, EVT MemVT,
668668 bool isVolatile, bool isNonTemporal, bool isInvariant,
669 unsigned Alignment, const MDNode *TBAAInfo = 0);
669 unsigned Alignment, const MDNode *TBAAInfo = 0,
670 const MDNode *Ranges = 0);
670671 SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
671672 EVT VT, DebugLoc dl,
672673 SDValue Chain, SDValue Ptr, SDValue Offset,
932932 /// Returns the TBAAInfo that describes the dereference.
933933 const MDNode *getTBAAInfo() const { return MMO->getTBAAInfo(); }
934934
935 /// Returns the Ranges that describes the dereference.
936 const MDNode *getRanges() const { return MMO->getRanges(); }
937
935938 /// getMemoryVT - Return the type of the in-memory value.
936939 EVT getMemoryVT() const { return MemoryVT; }
937940
196196 KnownOne.setBit(BitWidth - 1);
197197 }
198198
199 static void computeMaskedBitsLoad(const MDNode &Ranges, const APInt &Mask,
200 APInt &KnownZero) {
199 void llvm::computeMaskedBitsLoad(const MDNode &Ranges, const APInt &Mask,
200 APInt &KnownZero) {
201201 unsigned BitWidth = Mask.getBitWidth();
202202 unsigned NumRanges = Ranges.getNumOperands() / 2;
203203 assert(NumRanges >= 1);
194194 MachineMemOperand *
195195 MachineFunction::getMachineMemOperand(MachinePointerInfo PtrInfo, unsigned f,
196196 uint64_t s, unsigned base_alignment,
197 const MDNode *TBAAInfo) {
197 const MDNode *TBAAInfo,
198 const MDNode *Ranges) {
198199 return new (Allocator) MachineMemOperand(PtrInfo, f, s, base_alignment,
199 TBAAInfo);
200 TBAAInfo, Ranges);
200201 }
201202
202203 MachineMemOperand *
380380
381381 MachineMemOperand::MachineMemOperand(MachinePointerInfo ptrinfo, unsigned f,
382382 uint64_t s, unsigned int a,
383 const MDNode *TBAAInfo)
383 const MDNode *TBAAInfo,
384 const MDNode *Ranges)
384385 : PtrInfo(ptrinfo), Size(s),
385386 Flags((f & ((1 << MOMaxBits) - 1)) | ((Log2_32(a) + 1) << MOMaxBits)),
386 TBAAInfo(TBAAInfo) {
387 TBAAInfo(TBAAInfo), Ranges(Ranges) {
387388 assert((PtrInfo.V == 0 || isa(PtrInfo.V->getType())) &&
388389 "invalid pointer value");
389390 assert(getBaseAlignment() == a && "Alignment is not a power of 2!");
18881888 return;
18891889 }
18901890 case ISD::LOAD: {
1891 LoadSDNode *LD = cast(Op);
18911892 if (ISD::isZEXTLoad(Op.getNode())) {
1892 LoadSDNode *LD = cast(Op);
18931893 EVT VT = LD->getMemoryVT();
18941894 unsigned MemBits = VT.getScalarType().getSizeInBits();
18951895 KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - MemBits) & Mask;
1896 } else if (const MDNode *Ranges = LD->getRanges()) {
1897 computeMaskedBitsLoad(*Ranges, Mask, KnownZero);
18961898 }
18971899 return;
18981900 }
41694171 SDValue Ptr, SDValue Offset,
41704172 MachinePointerInfo PtrInfo, EVT MemVT,
41714173 bool isVolatile, bool isNonTemporal, bool isInvariant,
4172 unsigned Alignment, const MDNode *TBAAInfo) {
4174 unsigned Alignment, const MDNode *TBAAInfo,
4175 const MDNode *Ranges) {
41734176 assert(Chain.getValueType() == MVT::Other &&
41744177 "Invalid chain type");
41754178 if (Alignment == 0) // Ensure that codegen never sees alignment 0
41914194 MachineFunction &MF = getMachineFunction();
41924195 MachineMemOperand *MMO =
41934196 MF.getMachineMemOperand(PtrInfo, Flags, MemVT.getStoreSize(), Alignment,
4194 TBAAInfo);
4197 TBAAInfo, Ranges);
41954198 return getLoad(AM, ExtType, VT, dl, Chain, Ptr, Offset, MemVT, MMO);
41964199 }
41974200
42474250 MachinePointerInfo PtrInfo,
42484251 bool isVolatile, bool isNonTemporal,
42494252 bool isInvariant, unsigned Alignment,
4250 const MDNode *TBAAInfo) {
4253 const MDNode *TBAAInfo,
4254 const MDNode *Ranges) {
42514255 SDValue Undef = getUNDEF(Ptr.getValueType());
42524256 return getLoad(ISD::UNINDEXED, ISD::NON_EXTLOAD, VT, dl, Chain, Ptr, Undef,
4253 PtrInfo, VT, isVolatile, isNonTemporal, isInvariant, Alignment,
4254 TBAAInfo);
4257 PtrInfo, VT, isVolatile, isNonTemporal, isInvariant, Alignment,
4258 TBAAInfo, Ranges);
42554259 }
42564260
42574261 SDValue SelectionDAG::getExtLoad(ISD::LoadExtType ExtType, DebugLoc dl, EVT VT,
32143214 bool isInvariant = I.getMetadata("invariant.load") != 0;
32153215 unsigned Alignment = I.getAlignment();
32163216 const MDNode *TBAAInfo = I.getMetadata(LLVMContext::MD_tbaa);
3217 const MDNode *Ranges = I.getMetadata(LLVMContext::MD_range);
32173218
32183219 SmallVector ValueVTs;
32193220 SmallVector Offsets;
32613262 DAG.getConstant(Offsets[i], PtrVT));
32623263 SDValue L = DAG.getLoad(ValueVTs[i], getCurDebugLoc(), Root,
32633264 A, MachinePointerInfo(SV, Offsets[i]), isVolatile,
3264 isNonTemporal, isInvariant, Alignment, TBAAInfo);
3265 isNonTemporal, isInvariant, Alignment, TBAAInfo,
3266 Ranges);
32653267
32663268 Values[i] = L;
32673269 Chains[ChainI] = L.getValue(1);
0 ; RUN: llc < %s -march=x86-64 | FileCheck %s
1
2 define zeroext i1 @f1(i8* %x) {
3 entry:
4 %0 = load i8* %x, align 1, !range !0
5 %tobool = trunc i8 %0 to i1
6 ret i1 %tobool
7 }
8
9 ; CHECK: f1:
10 ; CHECK: movb (%rdi), %al
11 ; CHECK-NEXT: ret
12
13 !0 = metadata !{i8 0, i8 2}