Skip to content

Commit 1e710cf

Browse files
committed
[DAG] Add TLI::isTruncateFree(SDValue, EVT) wrapper.
Similar to the existing isZExtFree(SDValue, EVT) wrapper, this will allow targets to override for specific cases (e.g. free truncation of an ext/extload node). But for now its just used to wrap the existing isTruncateFree(EVT, EVT) call.
1 parent eea2176 commit 1e710cf

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,12 @@ class TargetLoweringBase {
28692869
getApproximateEVTForLLT(ToTy, DL, Ctx));
28702870
}
28712871

2872+
/// Return true if truncating the specific node Val to type VT2 is free.
2873+
virtual bool isTruncateFree(SDValue Val, EVT VT2) const {
2874+
// Fallback to type matching.
2875+
return isTruncateFree(Val.getValueType(), VT2);
2876+
}
2877+
28722878
virtual bool isProfitableToHoist(Instruction *I) const { return true; }
28732879

28742880
/// Return true if the extension represented by \p I is free.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13703,8 +13703,7 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
1370313703
if (N0.getOpcode() == ISD::AND &&
1370413704
N0.getOperand(0).getOpcode() == ISD::TRUNCATE &&
1370513705
N0.getOperand(1).getOpcode() == ISD::Constant &&
13706-
(!TLI.isTruncateFree(N0.getOperand(0).getOperand(0).getValueType(),
13707-
N0.getValueType()) ||
13706+
(!TLI.isTruncateFree(N0.getOperand(0).getOperand(0), N0.getValueType()) ||
1370813707
!TLI.isZExtFree(N0.getValueType(), VT))) {
1370913708
SDValue X = N0.getOperand(0).getOperand(0);
1371013709
X = DAG.getAnyExtOrTrunc(X, SDLoc(X), VT);
@@ -13935,8 +13934,7 @@ SDValue DAGCombiner::visitANY_EXTEND(SDNode *N) {
1393513934
if (N0.getOpcode() == ISD::AND &&
1393613935
N0.getOperand(0).getOpcode() == ISD::TRUNCATE &&
1393713936
N0.getOperand(1).getOpcode() == ISD::Constant &&
13938-
!TLI.isTruncateFree(N0.getOperand(0).getOperand(0).getValueType(),
13939-
N0.getValueType())) {
13937+
!TLI.isTruncateFree(N0.getOperand(0).getOperand(0), N0.getValueType())) {
1394013938
SDLoc DL(N);
1394113939
SDValue X = DAG.getAnyExtOrTrunc(N0.getOperand(0).getOperand(0), DL, VT);
1394213940
SDValue Y = DAG.getNode(ISD::ANY_EXTEND, DL, VT, N0.getOperand(1));
@@ -18855,8 +18853,7 @@ struct LoadedSlice {
1885518853
void addSliceGain(const LoadedSlice &LS) {
1885618854
// Each slice saves a truncate.
1885718855
const TargetLowering &TLI = LS.DAG->getTargetLoweringInfo();
18858-
if (!TLI.isTruncateFree(LS.Inst->getOperand(0).getValueType(),
18859-
LS.Inst->getValueType(0)))
18856+
if (!TLI.isTruncateFree(LS.Inst->getOperand(0), LS.Inst->getValueType(0)))
1886018857
++Truncates;
1886118858
// If there is a shift amount, this slice gets rid of it.
1886218859
if (LS.Shift)

0 commit comments

Comments
 (0)