[llvm] r186235 - Add a microoptimization for urem.
Nick Lewycky
nicholas at mxc.ca
Fri Jul 12 18:16:48 PDT 2013
Author: nicholas
Date: Fri Jul 12 20:16:47 2013
New Revision: 186235
URL: http://llvm.org/viewvc/llvm-project?rev=186235&view=rev
Log:
Add a microoptimization for urem.
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/rem.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=186235&r1=186234&r2=186235&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Fri Jul 12 20:16:47 2013
@@ -1125,6 +1125,13 @@ Instruction *InstCombiner::visitURem(Bin
return BinaryOperator::CreateAnd(Op0, Add);
}
+ // 1 urem X -> zext(X != 1)
+ if (match(Op0, m_One())) {
+ Value *Cmp = Builder->CreateICmpNE(Op1, Op0);
+ Value *Ext = Builder->CreateZExt(Cmp, I.getType());
+ return ReplaceInstUsesWith(I, Ext);
+ }
+
return 0;
}
Modified: llvm/trunk/test/Transforms/InstCombine/rem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/rem.ll?rev=186235&r1=186234&r2=186235&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/rem.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/rem.ll Fri Jul 12 20:16:47 2013
@@ -163,3 +163,12 @@ define i32 @test16(i32 %x, i32 %y) {
%rem = urem i32 %x, %add
ret i32 %rem
}
+
+define i32 @test17(i32 %X) {
+; CHECK: @test17
+; CHECK-NEXT: icmp ne i32 %X, 1
+; CHECK-NEXT: zext i1
+; CHECK-NEXT: ret
+ %A = urem i32 1, %X
+ ret i32 %A
+}
More information about the llvm-commits
mailing list