mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[InstCombine] fold udiv with sext bool divisor
Note: I didn't add a hasOneUse() check because the existing, related fold doesn't have that check. I suspect that the improved analysis and codegen make these some of the rare canonicalization cases where we allow an increase in instructions. llvm-svn: 335597
This commit is contained in:
parent
0c43fe0de7
commit
70547e8323
@ -954,9 +954,15 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) {
|
||||
|
||||
// Op0 / C where C is large (negative) --> zext (Op0 >= C)
|
||||
// TODO: Could use isKnownNegative() to handle non-constant values.
|
||||
Type *Ty = I.getType();
|
||||
if (match(Op1, m_Negative())) {
|
||||
Value *Cmp = Builder.CreateICmpUGE(Op0, Op1);
|
||||
return CastInst::CreateZExtOrBitCast(Cmp, I.getType());
|
||||
return CastInst::CreateZExtOrBitCast(Cmp, Ty);
|
||||
}
|
||||
// Op0 / (sext i1 X) --> zext (Op0 == -1) (if X is 0, the div is undefined)
|
||||
if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
|
||||
Value *Cmp = Builder.CreateICmpEQ(Op0, ConstantInt::getAllOnesValue(Ty));
|
||||
return CastInst::CreateZExtOrBitCast(Cmp, Ty);
|
||||
}
|
||||
|
||||
if (Instruction *NarrowDiv = narrowUDivURem(I, Builder))
|
||||
|
@ -98,8 +98,8 @@ define <2 x i64> @udiv_by_minus1_vec(<2 x i64> %x) {
|
||||
|
||||
define i32 @udiv_by_sext_all_ones(i1 %x, i32 %y) {
|
||||
; CHECK-LABEL: @udiv_by_sext_all_ones(
|
||||
; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[X:%.*]] to i32
|
||||
; CHECK-NEXT: [[DIV:%.*]] = udiv i32 [[Y:%.*]], [[SEXT]]
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[Y:%.*]], -1
|
||||
; CHECK-NEXT: [[DIV:%.*]] = zext i1 [[TMP1]] to i32
|
||||
; CHECK-NEXT: ret i32 [[DIV]]
|
||||
;
|
||||
%sext = sext i1 %x to i32
|
||||
@ -109,8 +109,8 @@ define i32 @udiv_by_sext_all_ones(i1 %x, i32 %y) {
|
||||
|
||||
define <2 x i32> @udiv_by_sext_all_ones_vec(<2 x i1> %x, <2 x i32> %y) {
|
||||
; CHECK-LABEL: @udiv_by_sext_all_ones_vec(
|
||||
; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[X:%.*]] to <2 x i32>
|
||||
; CHECK-NEXT: [[DIV:%.*]] = udiv <2 x i32> [[Y:%.*]], [[SEXT]]
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i32> [[Y:%.*]], <i32 -1, i32 -1>
|
||||
; CHECK-NEXT: [[DIV:%.*]] = zext <2 x i1> [[TMP1]] to <2 x i32>
|
||||
; CHECK-NEXT: ret <2 x i32> [[DIV]]
|
||||
;
|
||||
%sext = sext <2 x i1> %x to <2 x i32>
|
||||
|
Loading…
x
Reference in New Issue
Block a user