1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

Add a small transform: transform -(X<<Y) to (-X<<Y) when the shift has a single

use and X is free to negate.

llvm-svn: 94941
This commit is contained in:
Eli Friedman 2010-01-31 02:30:23 +00:00
parent 5458663492
commit 58c7936637
2 changed files with 15 additions and 0 deletions

View File

@ -676,6 +676,13 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
return BinaryOperator::CreateSDiv(Op1I->getOperand(0),
ConstantExpr::getNeg(DivRHS));
// 0 - (C << X) -> (-C << X)
if (Op1I->getOpcode() == Instruction::Shl)
if (ConstantInt *CSI = dyn_cast<ConstantInt>(Op0))
if (CSI->isZero())
if (Value *ShlLHSNeg = dyn_castNegVal(Op1I->getOperand(0)))
return BinaryOperator::CreateShl(ShlLHSNeg, Op1I->getOperand(1));
// X - X*C --> X * (1-C)
ConstantInt *C2 = 0;
if (dyn_castFoldableMul(Op1I, C2) == Op0) {

View File

@ -272,4 +272,12 @@ define i64 @test25(i8* %P, i64 %A){
; CHECK-NEXT: ret i64
}
define i32 @test26(i32 %x) {
%shl = shl i32 3, %x
%neg = sub i32 0, %shl
ret i32 %neg
; CHECK: @test26
; CHECK-NEXT: shl i32 -3
; CHECK-NEXT: ret i32
}