[InstCombine] remove one-use check for ctpop -> cttz

Two one-use checks were added with rGfdcb27105537,
but only the first one is necessary to limit an
increase in instruction count. The second transform
only creates one instruction, so it is always a
reasonable canonicalization/optimization.
This commit is contained in:
Sanjay Patel 2020-03-23 13:56:07 -04:00
parent 9e33c09647
commit a1fe6beb1e
2 changed files with 2 additions and 3 deletions

View File

@ -1343,8 +1343,7 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombiner &IC) {
}
// ctpop(~x & (x - 1)) -> cttz(x, false)
if (Op0->hasOneUse() &&
match(Op0,
if (match(Op0,
m_c_And(m_Not(m_Value(X)), m_Add(m_Deferred(X), m_AllOnes())))) {
Function *F =
Intrinsic::getDeclaration(II.getModule(), Intrinsic::cttz, Ty);

View File

@ -78,7 +78,7 @@ define i32 @ctpop2_multiuse(i32 %0) {
; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP0:%.*]], -1
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP0]], -1
; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[TMP3]], [[TMP2]]
; CHECK-NEXT: [[TMP5:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[TMP4]]), !range !0
; CHECK-NEXT: [[TMP5:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 false), !range !0
; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[TMP5]], [[TMP4]]
; CHECK-NEXT: ret i32 [[TMP6]]
;