diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2020-01-03 16:01:16 +0300 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2020-01-03 17:55:46 +0300 |
commit | 86403c0ff8930e6d4d21d94baa7384e54620f4cf (patch) | |
tree | 1c7ff062ffac1b7ea3fbf5e737237e20a37ada7c /llvm/lib/CodeGen | |
parent | d09ac032ee0012d11ae9f9d717eaa6a10cc22a75 (diff) | |
download | bcm5719-llvm-86403c0ff8930e6d4d21d94baa7384e54620f4cf.tar.gz bcm5719-llvm-86403c0ff8930e6d4d21d94baa7384e54620f4cf.zip |
[DAGCombiner] `~(add X, -1)` -> `neg X` fold
The fold 'A - (A & (B - 1))' -> 'A & (0 - B)'
added in 8dab0a4a7d691f2704f1079538e0ef29548db159
is too specific. It should just be 'A - (A & B)' -> 'A & (~B)',
but we currently fail to sink that '~' into `(B - 1)`.
Name: ~(X - 1) -> (0 - X)
%o = add i32 %X, -1
%r = xor i32 %o, -1
=>
%r = sub i32 0, %X
https://rise4fun.com/Alive/rjU
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index dad47944a0f..5a8b4d456d9 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -7131,6 +7131,13 @@ SDValue DAGCombiner::visitXOR(SDNode *N) { DAG.getAllOnesConstant(DL, VT)); } + // fold (not (add X, -1)) -> (neg X) + if (isAllOnesConstant(N1) && N0.getOpcode() == ISD::ADD && + isAllOnesOrAllOnesSplat(N0.getOperand(1))) { + return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), + N0.getOperand(0)); + } + // fold (xor (and x, y), y) -> (and (not x), y) if (N0Opcode == ISD::AND && N0.hasOneUse() && N0->getOperand(1) == N1) { SDValue X = N0.getOperand(0); |