[llvm-commits] [llvm] r130614 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp test/Transforms/InstCombine/div.ll
Benjamin Kramer
benny.kra at googlemail.com
Sat Apr 30 11:16:00 PDT 2011
Author: d0k
Date: Sat Apr 30 13:16:00 2011
New Revision: 130614
URL: http://llvm.org/viewvc/llvm-project?rev=130614&view=rev
Log:
Use SimplifyDemandedBits on div instructions.
This folds away silly stuff like (a&255)/1000 -> 0.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/div.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=130614&r1=130613&r2=130614&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Sat Apr 30 13:16:00 2011
@@ -320,6 +320,10 @@
}
}
+ // 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
Modified: llvm/trunk/test/Transforms/InstCombine/div.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/div.ll?rev=130614&r1=130613&r2=130614&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/div.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/div.ll Sat Apr 30 13:16:00 2011
@@ -111,3 +111,10 @@
; 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
+}
More information about the llvm-commits
mailing list