summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2020-01-03 15:38:53 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2020-01-03 17:55:45 +0300
commit3d492d7503d197246115eb38e7b1b61143d0c99f (patch)
tree7f6a9099af90c17c6ee5173c1c26c944500dd065 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parente4de8db67eb7a2d64cba078c38f0fd25499013c1 (diff)
downloadbcm5719-llvm-3d492d7503d197246115eb38e7b1b61143d0c99f.tar.gz
bcm5719-llvm-3d492d7503d197246115eb38e7b1b61143d0c99f.zip
[DAGCombine][X86][Thumb2/LowOverheadLoops] `A - (A & C)` -> `A & (~C)` fold (PR44448)
While we do manage to fold integer-typed IR in middle-end, we can't do that for the main motivational case of pointers. There is @llvm.ptrmask() intrinsic which may or may not be helpful, but i'm not sure it is fully considered canonical yet, not everything is fully aware of it likely. Name: PR44448 ptr - (ptr & C) -> ptr & (~C) %bias = and i32 %ptr, C %r = sub i32 %ptr, %bias => %r = and i32 %ptr, ~C See https://bugs.llvm.org/show_bug.cgi?id=44448 https://reviews.llvm.org/D71499
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index cd6d33ffa9e..dad47944a0f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -3119,6 +3119,16 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
}
}
+ // A - (A & C) -> A & (~C)
+ if (N1.getOpcode() == ISD::AND && N1.getOperand(0) == N0 &&
+ isConstantOrConstantVector(N1.getOperand(1), /*NoOpaques=*/true)) {
+ SDValue InvC =
+ DAG.FoldConstantArithmetic(ISD::XOR, DL, VT, N1.getOperand(1).getNode(),
+ DAG.getAllOnesConstant(DL, VT).getNode());
+ assert(InvC && "Constant folding failed");
+ return DAG.getNode(ISD::AND, DL, VT, N0, InvC);
+ }
+
// fold (X - (-Y * Z)) -> (X + (Y * Z))
if (N1.getOpcode() == ISD::MUL && N1.hasOneUse()) {
if (N1.getOperand(0).getOpcode() == ISD::SUB &&
OpenPOWER on IntegriCloud