Add a microoptimization for urem.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186235 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2013-07-13 01:16:47 +00:00
parent 12c74dc2c2
commit 75681bb302
2 changed files with 16 additions and 0 deletions

View File

@ -1125,6 +1125,13 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) {
return BinaryOperator::CreateAnd(Op0, Add); 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; return 0;
} }

View File

@ -163,3 +163,12 @@ define i32 @test16(i32 %x, i32 %y) {
%rem = urem i32 %x, %add %rem = urem i32 %x, %add
ret i32 %rem 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
}