[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Apr 9 14:44:11 PDT 2005
Changes in directory llvm/lib/CodeGen/SelectionDAG:
SelectionDAG.cpp updated: 1.66 -> 1.67
---
Log message:
add a little peephole optimization. This allows us to codegen:
int a(short i) {
return i & 1;
}
as
_a:
andi. r3, r3, 1
blr
instead of:
_a:
rlwinm r2, r3, 0, 16, 31
andi. r3, r2, 1
blr
on ppc. It should also help the other risc targets.
---
Diffs of the changes: (+11 -0)
SelectionDAG.cpp | 11 +++++++++++
1 files changed, 11 insertions(+)
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.66 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.67
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.66 Sat Apr 9 00:15:53 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sat Apr 9 16:43:54 2005
@@ -766,6 +766,17 @@
if (!C2) return N2; // X and 0 -> 0
if (N2C->isAllOnesValue())
return N1; // X and -1 -> X
+
+ // and (zero_extend_inreg x:16:32), 1 -> and x, 1
+ if (N1.getOpcode() == ISD::ZERO_EXTEND_INREG ||
+ N1.getOpcode() == ISD::SIGN_EXTEND_INREG) {
+ // If we are masking out the part of our input that was extended, just
+ // mask the input to the extension directly.
+ unsigned ExtendBits =
+ MVT::getSizeInBits(cast<MVTSDNode>(N1)->getExtraValueType());
+ if ((C2 & (~0ULL << ExtendBits)) == 0)
+ return getNode(ISD::AND, VT, N1.getOperand(0), N2);
+ }
break;
case ISD::OR:
if (!C2)return N1; // X or 0 -> X
More information about the llvm-commits
mailing list