diff options
| author | Dan Gohman <gohman@apple.com> | 2009-02-24 02:00:40 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-02-24 02:00:40 +0000 |
| commit | 4f356bb9b0a9dfc6e3d195d13ba45b4cfc1ed4c1 (patch) | |
| tree | c121dab1093a2c0a8ee18730e801999f84d4adc6 | |
| parent | 5d1f458f0fc996dd15c8047d358963fe623878e8 (diff) | |
| download | bcm5719-llvm-4f356bb9b0a9dfc6e3d195d13ba45b4cfc1ed4c1.tar.gz bcm5719-llvm-4f356bb9b0a9dfc6e3d195d13ba45b4cfc1ed4c1.zip | |
Fix a ValueTracking rule: RHS means operand 1, not 0. Add a simple
ashr instcombine to help expose this code. And apply the fix to
SelectionDAG's copy of this code too.
llvm-svn: 65364
| -rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 7 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/ashr-nop.ll | 8 |
4 files changed, 16 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 7ac138b90ef..20fa69ea24f 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -625,7 +625,7 @@ unsigned llvm::ComputeNumSignBits(Value *V, TargetData *TD, unsigned Depth) { if (Tmp == 1) return 1; // Early out. // Special case decrementing a value (ADD X, -1): - if (ConstantInt *CRHS = dyn_cast<ConstantInt>(U->getOperand(0))) + if (ConstantInt *CRHS = dyn_cast<ConstantInt>(U->getOperand(1))) if (CRHS->isAllOnesValue()) { APInt KnownZero(TyBits, 0), KnownOne(TyBits, 0); APInt Mask = APInt::getAllOnesValue(TyBits); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 66356f5f9af..358c9703a80 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2008,7 +2008,7 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, unsigned Depth) const{ if (Tmp == 1) return 1; // Early out. // Special case decrementing a value (ADD X, -1): - if (ConstantSDNode *CRHS = dyn_cast<ConstantSDNode>(Op.getOperand(0))) + if (ConstantSDNode *CRHS = dyn_cast<ConstantSDNode>(Op.getOperand(1))) if (CRHS->isAllOnesValue()) { APInt KnownZero, KnownOne; APInt Mask = APInt::getAllOnesValue(VTBits); diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 7f2cab96ec5..62554a5e91f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7031,7 +7031,12 @@ Instruction *InstCombiner::visitAShr(BinaryOperator &I) { MaskedValueIsZero(Op0, APInt::getSignBit(I.getType()->getPrimitiveSizeInBits()))) return BinaryOperator::CreateLShr(Op0, I.getOperand(1)); - + + // Arithmetic shifting an all-sign-bit value is a no-op. + unsigned NumSignBits = ComputeNumSignBits(Op0); + if (NumSignBits == Op0->getType()->getPrimitiveSizeInBits()) + return ReplaceInstUsesWith(I, Op0); + return 0; } diff --git a/llvm/test/Transforms/InstCombine/ashr-nop.ll b/llvm/test/Transforms/InstCombine/ashr-nop.ll new file mode 100644 index 00000000000..bb0da346b0c --- /dev/null +++ b/llvm/test/Transforms/InstCombine/ashr-nop.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep ashr + +define i32 @foo(i32 %x) { + %o = and i32 %x, 1 + %n = add i32 %o, -1 + %t = ashr i32 %n, 17 + ret i32 %t +} |

