summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-09-18 22:05:35 +0000
committerSanjay Patel <spatel@rotateright.com>2017-09-18 22:05:35 +0000
commitf31b1a00ea4d2916dfcc0fd476bebdb0fc60ff9f (patch)
tree58b2fbe068da8af4c73d501d153c817d79ce91b0 /llvm/lib
parent1468677cbe9a39a8032a2e3e5363ffe74be96b40 (diff)
downloadbcm5719-llvm-f31b1a00ea4d2916dfcc0fd476bebdb0fc60ff9f.tar.gz
bcm5719-llvm-f31b1a00ea4d2916dfcc0fd476bebdb0fc60ff9f.zip
[DAGCombiner] fold assertzexts separated by trunc
If we have an AssertZext of a truncated value that has already been AssertZext'ed, we can assert on the wider source op to improve the zext-y knowledge: assert (trunc (assert X, i8) to iN), i1 --> trunc (assert X, i1) to iN This moves a fold from being Mips-specific to general combining, and x86 shows improvements. Differential Revision: https://reviews.llvm.org/D37017 llvm-svn: 313577
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp27
-rw-r--r--llvm/lib/Target/Mips/MipsISelLowering.cpp33
2 files changed, 25 insertions, 35 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index b69a5f4738c..018ea1b48b8 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7970,16 +7970,39 @@ SDValue DAGCombiner::visitANY_EXTEND(SDNode *N) {
return SDValue();
}
+// TODO: These transforms should work with AssertSext too.
+// Change the function name, comments, opcode references, and caller.
SDValue DAGCombiner::visitAssertZext(SDNode *N) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
- EVT EVT = cast<VTSDNode>(N1)->getVT();
+ EVT AssertVT = cast<VTSDNode>(N1)->getVT();
// fold (assertzext (assertzext x, vt), vt) -> (assertzext x, vt)
if (N0.getOpcode() == ISD::AssertZext &&
- EVT == cast<VTSDNode>(N0.getOperand(1))->getVT())
+ AssertVT == cast<VTSDNode>(N0.getOperand(1))->getVT())
return N0;
+ if (N0.getOpcode() == ISD::TRUNCATE && N0.hasOneUse() &&
+ N0.getOperand(0).getOpcode() == ISD::AssertZext) {
+ // We have an assert, truncate, assert sandwich. Make one stronger assert
+ // by asserting on the smallest asserted type to the larger source type.
+ // This eliminates the later assert:
+ // assert (trunc (assert X, i8) to iN), i1 --> trunc (assert X, i1) to iN
+ // assert (trunc (assert X, i1) to iN), i8 --> trunc (assert X, i1) to iN
+ SDValue BigA = N0.getOperand(0);
+ EVT BigA_AssertVT = cast<VTSDNode>(BigA.getOperand(1))->getVT();
+ assert(BigA_AssertVT.bitsLE(N0.getValueType()) &&
+ "Asserting zero/sign-extended bits from a type larger than the "
+ "truncated destination does not provide information");
+
+ SDLoc DL(N);
+ EVT MinAssertVT = AssertVT.bitsLT(BigA_AssertVT) ? AssertVT : BigA_AssertVT;
+ SDValue MinAssertVTVal = DAG.getValueType(MinAssertVT);
+ SDValue NewAssert = DAG.getNode(ISD::AssertZext, DL, BigA.getValueType(),
+ BigA.getOperand(0), MinAssertVTVal);
+ return DAG.getNode(ISD::TRUNCATE, DL, N->getValueType(0), NewAssert);
+ }
+
return SDValue();
}
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 4c8f87f9381..06874eb9796 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -1112,37 +1112,6 @@ static SDValue performADDCombine(SDNode *N, SelectionDAG &DAG,
return DAG.getNode(ISD::ADD, DL, ValTy, Add1, Lo);
}
-static SDValue performAssertZextCombine(SDNode *N, SelectionDAG &DAG,
- TargetLowering::DAGCombinerInfo &DCI,
- const MipsSubtarget &Subtarget) {
- SDValue N0 = N->getOperand(0);
- EVT NarrowerVT = cast<VTSDNode>(N->getOperand(1))->getVT();
-
- if (N0.getOpcode() != ISD::TRUNCATE)
- return SDValue();
-
- if (N0.getOperand(0).getOpcode() != ISD::AssertZext)
- return SDValue();
-
- // fold (AssertZext (trunc (AssertZext x))) -> (trunc (AssertZext x))
- // if the type of the extension of the innermost AssertZext node is
- // smaller from that of the outermost node, eg:
- // (AssertZext:i32 (trunc:i32 (AssertZext:i64 X, i32)), i8)
- // -> (trunc:i32 (AssertZext X, i8))
- SDValue WiderAssertZext = N0.getOperand(0);
- EVT WiderVT = cast<VTSDNode>(WiderAssertZext->getOperand(1))->getVT();
-
- if (NarrowerVT.bitsLT(WiderVT)) {
- SDValue NewAssertZext = DAG.getNode(
- ISD::AssertZext, SDLoc(N), WiderAssertZext.getValueType(),
- WiderAssertZext.getOperand(0), DAG.getValueType(NarrowerVT));
- return DAG.getNode(ISD::TRUNCATE, SDLoc(N), N->getValueType(0),
- NewAssertZext);
- }
-
- return SDValue();
-}
-
static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
TargetLowering::DAGCombinerInfo &DCI,
const MipsSubtarget &Subtarget) {
@@ -1215,8 +1184,6 @@ SDValue MipsTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI)
return performORCombine(N, DAG, DCI, Subtarget);
case ISD::ADD:
return performADDCombine(N, DAG, DCI, Subtarget);
- case ISD::AssertZext:
- return performAssertZextCombine(N, DAG, DCI, Subtarget);
case ISD::SHL:
return performSHLCombine(N, DAG, DCI, Subtarget);
case ISD::SUB:
OpenPOWER on IntegriCloud