[llvm] r291296 - [InstSimplify] Optimize away udivs in the presence of range metadata
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 6 14:58:02 PST 2017
Author: majnemer
Date: Fri Jan 6 16:58:02 2017
New Revision: 291296
URL: http://llvm.org/viewvc/llvm-project?rev=291296&view=rev
Log:
[InstSimplify] Optimize away udivs in the presence of range metadata
We know that udiv %V, C can be optimized away to 0 if %V is ult C.
Added:
llvm/trunk/test/Transforms/InstSimplify/div.ll
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=291296&r1=291295&r2=291296&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Fri Jan 6 16:58:02 2017
@@ -1106,6 +1106,16 @@ static Value *SimplifyUDivInst(Value *Op
if (Value *V = SimplifyDiv(Instruction::UDiv, Op0, Op1, Q, MaxRecurse))
return V;
+ // udiv %V, C -> 0 if %V < C
+ if (MaxRecurse) {
+ if (Constant *C = dyn_cast_or_null<Constant>(SimplifyICmpInst(
+ ICmpInst::ICMP_ULT, Op0, Op1, Q, MaxRecurse - 1))) {
+ if (C->isAllOnesValue()) {
+ return Constant::getNullValue(Op0->getType());
+ }
+ }
+ }
+
return nullptr;
}
Added: llvm/trunk/test/Transforms/InstSimplify/div.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/div.ll?rev=291296&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/div.ll (added)
+++ llvm/trunk/test/Transforms/InstSimplify/div.ll Fri Jan 6 16:58:02 2017
@@ -0,0 +1,15 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+declare i32 @external()
+
+define i32 @div1() {
+; CHECK-LABEL: @div1(
+; CHECK: [[CALL:%.*]] = call i32 @external(), !range !0
+; CHECK-NEXT: ret i32 0
+;
+ %call = call i32 @external(), !range !0
+ %urem = udiv i32 %call, 3
+ ret i32 %urem
+}
+
+!0 = !{i32 0, i32 3}
More information about the llvm-commits
mailing list