diff options
author | Chris Lattner <sabre@nondot.org> | 2007-04-17 19:03:21 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-04-17 19:03:21 +0000 |
commit | 9ad5915559a97b7adc6d74b3f64eff5922487c6c (patch) | |
tree | 3c9c5a1251b82bacf79b4120c27f67936ebecd20 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | 2a4054bddb06cfcc71ab276157d14360a3f86c7d (diff) | |
download | bcm5719-llvm-9ad5915559a97b7adc6d74b3f64eff5922487c6c.tar.gz bcm5719-llvm-9ad5915559a97b7adc6d74b3f64eff5922487c6c.zip |
SIGN_EXTEND_INREG does not demand its top bits. Give SimplifyDemandedBits
a chance to hack on it. This compiles:
int baz(long long a) { return (short)(((int)(a >>24)) >> 9); }
into:
_baz:
slwi r2, r3, 8
srwi r2, r2, 9
extsh r3, r2
blr
instead of:
_baz:
srwi r2, r4, 24
rlwimi r2, r3, 8, 0, 23
srwi r2, r2, 9
extsh r3, r2
blr
This implements CodeGen/PowerPC/sign_ext_inreg1.ll
llvm-svn: 36212
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 9ed09f24c16..19eff10f4d0 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2429,10 +2429,15 @@ SDOperand DAGCombiner::visitSIGN_EXTEND_INREG(SDNode *N) { return DAG.getNode(ISD::SIGN_EXTEND_INREG, VT, N0.getOperand(0), N1); } - // fold (sext_in_reg x) -> (zext_in_reg x) if the sign bit is zero + // fold (sext_in_reg x) -> (zext_in_reg x) if the sign bit is known zero. if (TLI.MaskedValueIsZero(N0, 1ULL << (EVTBits-1))) return DAG.getZeroExtendInReg(N0, EVT); + // fold operands of sext_in_reg based on knowledge that the top bits are not + // demanded. + if (SimplifyDemandedBits(SDOperand(N, 0))) + return SDOperand(N, 0); + // fold (sext_in_reg (load x)) -> (smaller sextload x) // fold (sext_in_reg (srl (load x), c)) -> (smaller sextload (x+c/evtbits)) SDOperand NarrowLoad = ReduceLoadWidth(N); |