1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

preserve NUW/NSW when transforming add x,x

llvm-svn: 125711
This commit is contained in:
Chris Lattner 2011-02-17 02:23:02 +00:00
parent 79947d56ea
commit 6e936c247f
2 changed files with 15 additions and 2 deletions

View File

@ -147,8 +147,13 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
return BinaryOperator::CreateXor(LHS, RHS);
// X + X --> X << 1
if (LHS == RHS && I.getType()->isIntegerTy())
return BinaryOperator::CreateShl(LHS, ConstantInt::get(I.getType(), 1));
if (LHS == RHS && I.getType()->isIntegerTy()) {
BinaryOperator *New =
BinaryOperator::CreateShl(LHS, ConstantInt::get(I.getType(), 1));
New->setHasNoSignedWrap(I.hasNoSignedWrap());
New->setHasNoUnsignedWrap(I.hasNoUnsignedWrap());
return New;
}
// -A + B --> B - A
// -A + -B --> -(A + B)

View File

@ -33,3 +33,11 @@ define i32 @test3(i32 %A) {
; CHECK-NEXT: ret i32
}
define i32 @test4(i32 %A) {
%B = add nuw i32 %A, %A
ret i32 %B
; CHECK: @test4
; CHECK-NEXT: %B = shl nuw i32 %A, 1
; CHECK-NEXT: ret i32 %B
}