diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-03-28 15:46:02 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-03-28 15:46:02 +0000 |
commit | ffa8d3def7615f4311ddb6c3a8a6f200bf2af825 (patch) | |
tree | 9c043e8c1df2df5247529a6d44871e86b783dcf2 /llvm/lib/CodeGen | |
parent | e7815282786a25de5c193e9804a2b10d1f07e530 (diff) | |
download | bcm5719-llvm-ffa8d3def7615f4311ddb6c3a8a6f200bf2af825.tar.gz bcm5719-llvm-ffa8d3def7615f4311ddb6c3a8a6f200bf2af825.zip |
[DAGCombiner] fold sext into negation
As noted in D59818:
%z = zext i8 %x to i32
%neg = sub i32 0, %z
%r = sext i32 %neg to i64
=>
%z2 = zext i8 %x to i64
%r = sub i64 0, %z2
https://rise4fun.com/Alive/KzSR
llvm-svn: 357178
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 1c44a5d5ce3..c24aafe5910 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -9030,6 +9030,16 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) { if (SDValue NewVSel = matchVSelectOpSizesWithSetCC(N)) return NewVSel; + // Eliminate this sign extend by doing a negation in the destination type: + // sext i32 (0 - (zext i8 X to i32)) to i64 --> 0 - (zext i8 X to i64) + if (N0.getOpcode() == ISD::SUB && N0.hasOneUse() && + isNullOrNullSplat(N0.getOperand(0)) && + N0.getOperand(1).getOpcode() == ISD::ZERO_EXTEND && + TLI.isOperationLegalOrCustom(ISD::SUB, VT)) { + SDValue Zext = DAG.getZExtOrTrunc(N0.getOperand(1).getOperand(0), DL, VT); + return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), Zext); + } + return SDValue(); } |