From: David Majnemer Date: Sat, 22 Nov 2014 20:00:38 +0000 (+0000) Subject: InstCombine: Propagate exact for (sdiv X, Y) -> (udiv X, Y) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec6e481bc5f77188efeccca73b5eafcc9eb2b663;p=platform%2Fupstream%2Fllvm.git InstCombine: Propagate exact for (sdiv X, Y) -> (udiv X, Y) llvm-svn: 222624 --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index b79f55e..216177f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1097,7 +1097,9 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { if (MaskedValueIsZero(Op0, Mask, 0, &I)) { if (MaskedValueIsZero(Op1, Mask, 0, &I)) { // X sdiv Y -> X udiv Y, iff X and Y don't have sign bit set - return BinaryOperator::CreateUDiv(Op0, Op1, I.getName()); + auto *BO = BinaryOperator::CreateUDiv(Op0, Op1, I.getName()); + BO->setIsExact(I.isExact()); + return BO; } if (match(Op1, m_Shl(m_Power2(), m_Value()))) { diff --git a/llvm/test/Transforms/InstCombine/div.ll b/llvm/test/Transforms/InstCombine/div.ll index f4166ec..cfe346e 100644 --- a/llvm/test/Transforms/InstCombine/div.ll +++ b/llvm/test/Transforms/InstCombine/div.ll @@ -304,3 +304,13 @@ define <2 x i64> @test34(<2 x i64> %x) nounwind { ; CHECK-NEXT: sdiv exact <2 x i64> %x, ; CHECK-NEXT: ret <2 x i64> } + +define i32 @test35(i32 %A) { + %and = and i32 %A, 2147483647 + %mul = sdiv exact i32 %and, 2147483647 + ret i32 %mul +; CHECK-LABEL: @test35( +; CHECK-NEXT: %[[and:.*]] = and i32 %A, 2147483647 +; CHECK-NEXT: %[[udiv:.*]] = udiv exact i32 %[[and]], 2147483647 +; CHECK-NEXT: ret i32 %[[udiv]] +}