[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Apr 25 14:20:45 PDT 2005
Changes in directory llvm/lib/CodeGen/SelectionDAG:
SelectionDAG.cpp updated: 1.93 -> 1.94
---
Log message:
implement some more logical compares with constants, so that:
int foo1(int x, int y) {
int t1 = x >= 0;
int t2 = y >= 0;
return t1 & t2;
}
int foo2(int x, int y) {
int t1 = x == -1;
int t2 = y == -1;
return t1 & t2;
}
produces:
_foo1:
or r2, r4, r3
srwi r2, r2, 31
xori r3, r2, 1
blr
_foo2:
and r2, r4, r3
addic r2, r2, 1
li r2, 0
addze r3, r2
blr
instead of:
_foo1:
srwi r2, r4, 31
xori r2, r2, 1
srwi r3, r3, 31
xori r3, r3, 1
and r3, r2, r3
blr
_foo2:
addic r2, r4, 1
li r2, 0
addze r2, r2
addic r3, r3, 1
li r3, 0
addze r3, r3
and r3, r2, r3
blr
---
Diffs of the changes: (+20 -7)
SelectionDAG.cpp | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.93 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.94
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.93 Mon Apr 25 16:03:25 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Mon Apr 25 16:20:28 2005
@@ -1060,17 +1060,30 @@
SDOperand LR = LHS->getOperand(1), RR = RHS->getOperand(1);
ISD::CondCode Op2 = RHS->getCondition();
- // (X != 0) | (Y != 0) -> (X|Y != 0)
- // (X == 0) & (Y == 0) -> (X|Y == 0)
- // (X < 0) | (Y < 0) -> (X|Y < 0)
if (LR == RR && isa<ConstantSDNode>(LR) &&
- cast<ConstantSDNode>(LR)->getValue() == 0 &&
Op2 == LHS->getCondition() && MVT::isInteger(LL.getValueType())) {
- if ((Op2 == ISD::SETEQ && Opcode == ISD::AND) ||
- (Op2 == ISD::SETNE && Opcode == ISD::OR) ||
- (Op2 == ISD::SETLT && Opcode == ISD::OR))
+ // (X != 0) | (Y != 0) -> (X|Y != 0)
+ // (X == 0) & (Y == 0) -> (X|Y == 0)
+ // (X < 0) | (Y < 0) -> (X|Y < 0)
+ if (cast<ConstantSDNode>(LR)->getValue() == 0 &&
+ ((Op2 == ISD::SETEQ && Opcode == ISD::AND) ||
+ (Op2 == ISD::SETNE && Opcode == ISD::OR) ||
+ (Op2 == ISD::SETLT && Opcode == ISD::OR)))
return getSetCC(Op2, VT,
getNode(ISD::OR, LR.getValueType(), LL, RL), LR);
+
+ if (cast<ConstantSDNode>(LR)->isAllOnesValue()) {
+ // (X == -1) & (Y == -1) -> (X&Y == -1)
+ // (X != -1) | (Y != -1) -> (X&Y != -1)
+ if ((Opcode == ISD::AND && Op2 == ISD::SETEQ) ||
+ (Opcode == ISD::OR && Op2 == ISD::SETNE))
+ return getSetCC(Op2, VT,
+ getNode(ISD::AND, LR.getValueType(), LL, RL), LR);
+ // (X > -1) & (Y > -1) -> (X|Y > -1)
+ if (Opcode == ISD::AND && Op2 == ISD::SETGT)
+ return getSetCC(Op2, VT,
+ getNode(ISD::OR, LR.getValueType(), LL, RL), LR);
+ }
}
// (X op1 Y) | (Y op2 X) -> (X op1 Y) | (X swapop2 Y)
More information about the llvm-commits
mailing list