diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-04-30 18:16:00 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-04-30 18:16:00 +0000 |
commit | 57b3df59b92c36441c931381e57df35f1959cf4b (patch) | |
tree | 5f3cdf4b4c3c6af0891f2182597e554c85f30293 | |
parent | 6a50bbd284da03f577c16e1abe50042e3b3d7eb6 (diff) | |
download | bcm5719-llvm-57b3df59b92c36441c931381e57df35f1959cf4b.tar.gz bcm5719-llvm-57b3df59b92c36441c931381e57df35f1959cf4b.zip |
Use SimplifyDemandedBits on div instructions.
This folds away silly stuff like (a&255)/1000 -> 0.
llvm-svn: 130614
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 4 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/div.ll | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 66513874815..b4f4da6fb0e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -320,6 +320,10 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { } } + // See if we can fold away this div instruction. + if (SimplifyDemandedInstructionBits(I)) + return &I; + // (X - (X rem Y)) / Y -> X / Y; usually originates as ((X / Y) * Y) / Y Value *X = 0, *Z = 0; if (match(Op0, m_Sub(m_Value(X), m_Value(Z)))) { // (X - Z) / Y; Y = Op1 diff --git a/llvm/test/Transforms/InstCombine/div.ll b/llvm/test/Transforms/InstCombine/div.ll index 7ef640b4203..2e24f19dce4 100644 --- a/llvm/test/Transforms/InstCombine/div.ll +++ b/llvm/test/Transforms/InstCombine/div.ll @@ -111,3 +111,10 @@ define i32 @test13(i32 %x) nounwind { ; CHECK-NEXT: ret i32 1 } +define i32 @test14(i8 %x) nounwind { + %zext = zext i8 %x to i32 + %div = udiv i32 %zext, 257 ; 0 + ret i32 %div +; CHECK: @test14 +; CHECK-NEXT: ret i32 0 +} |