Skip to content

Commit 19b50e8

Browse files
committed
DAG: Add computeKnownBitsForFrameIndex
Some of the AMDGPU stack addressing modes require knowing the sign bit is zero. We used to accomplish this by custom lowering frame indexes, and then putting an AssertZext around a TargetFrameIndex. This required specifically looking for the AssextZext + frame index pattern which was moderately disgusting. The same could probably be accomplished with a target specific node, but would still require special handling of frame indexes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317671 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 600fc9c commit 19b50e8

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

include/llvm/Target/TargetLowering.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,6 +2678,15 @@ class TargetLowering : public TargetLoweringBase {
26782678
const SelectionDAG &DAG,
26792679
unsigned Depth = 0) const;
26802680

2681+
/// Determine which of the bits of FrameIndex \p FIOp are known to be 0.
2682+
/// Default implementation computes low bits based on alignment
2683+
/// information. This should preserve known bits passed into it.
2684+
virtual void computeKnownBitsForFrameIndex(const SDValue FIOp,
2685+
KnownBits &Known,
2686+
const APInt &DemandedElts,
2687+
const SelectionDAG &DAG,
2688+
unsigned Depth = 0) const;
2689+
26812690
/// This method can be implemented by targets that want to expose additional
26822691
/// information about sign bits to the DAG Combiner. The DemandedElts
26832692
/// argument allows us to only collect the minimum sign bits that are shared

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,11 +2893,7 @@ void SelectionDAG::computeKnownBits(SDValue Op, KnownBits &Known,
28932893
}
28942894
case ISD::FrameIndex:
28952895
case ISD::TargetFrameIndex:
2896-
if (unsigned Align = InferPtrAlignment(Op)) {
2897-
// The low bits are known zero if the pointer is aligned.
2898-
Known.Zero.setLowBits(Log2_32(Align));
2899-
break;
2900-
}
2896+
TLI->computeKnownBitsForFrameIndex(Op, Known, DemandedElts, *this, Depth);
29012897
break;
29022898

29032899
default:

lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,19 @@ void TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
12881288
Known.resetAll();
12891289
}
12901290

1291+
void TargetLowering::computeKnownBitsForFrameIndex(const SDValue Op,
1292+
KnownBits &Known,
1293+
const APInt &DemandedElts,
1294+
const SelectionDAG &DAG,
1295+
unsigned Depth) const {
1296+
assert(isa<FrameIndexSDNode>(Op) && "expected FrameIndex");
1297+
1298+
if (unsigned Align = DAG.InferPtrAlignment(Op)) {
1299+
// The low bits are known zero if the pointer is aligned.
1300+
Known.Zero.setLowBits(Log2_32(Align));
1301+
}
1302+
}
1303+
12911304
/// This method can be implemented by targets that want to expose additional
12921305
/// information about sign bits to the DAG Combiner.
12931306
unsigned TargetLowering::ComputeNumSignBitsForTargetNode(SDValue Op,

0 commit comments

Comments
 (0)