diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-11-22 18:16:54 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-11-22 18:16:54 +0000 |
| commit | a3aeb15613afba82349f5cf8575ab88475342395 (patch) | |
| tree | f703343e1b64b5016a8a990d16207d83effeb0d7 | |
| parent | 94a272d47980c61dd8fdf839c1307de406a9a58e (diff) | |
| download | bcm5719-llvm-a3aeb15613afba82349f5cf8575ab88475342395.tar.gz bcm5719-llvm-a3aeb15613afba82349f5cf8575ab88475342395.zip | |
InstCombine: Propagate exact in (udiv (lshr X,C1),C2) -> (udiv x,C1<<C2)
llvm-svn: 222620
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 9 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/div.ll | 9 |
2 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 010625a7157..2befe1934f4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -997,9 +997,14 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { match(Op1, m_APInt(C2))) { bool Overflow; APInt C2ShlC1 = C2->ushl_ov(*C1, Overflow); - if (!Overflow) - return BinaryOperator::CreateUDiv( + if (!Overflow) { + bool IsExact = I.isExact() && match(Op0, m_Exact(m_Value())); + BinaryOperator *BO = BinaryOperator::CreateUDiv( X, ConstantInt::get(X->getType(), C2ShlC1)); + if (IsExact) + BO->setIsExact(); + return BO; + } } } diff --git a/llvm/test/Transforms/InstCombine/div.ll b/llvm/test/Transforms/InstCombine/div.ll index 5af86680697..585b04a4d5d 100644 --- a/llvm/test/Transforms/InstCombine/div.ll +++ b/llvm/test/Transforms/InstCombine/div.ll @@ -286,3 +286,12 @@ define i32 @test32(i32 %a, i32 %b) { ; CHECK-NEXT: %[[div:.*]] = udiv i32 %a, %[[shr]] ; CHECK-NEXT: ret i32 } + +define <2 x i64> @test33(<2 x i64> %x) nounwind { + %shr = lshr exact <2 x i64> %x, <i64 5, i64 5> + %div = udiv exact <2 x i64> %shr, <i64 6, i64 6> + ret <2 x i64> %div +; CHECK-LABEL: @test33( +; CHECK-NEXT: udiv exact <2 x i64> %x, <i64 192, i64 192> +; CHECK-NEXT: ret <2 x i64> +} |

