From 6d970e83fac56cefc18d352a760cddb1c6d29e09 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sat, 11 Sep 2021 20:17:10 +0100 Subject: [PATCH] [InstCombine] Add PR51784 test cases --- llvm/test/Transforms/InstCombine/ctpop-cttz.ll | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/ctpop-cttz.ll b/llvm/test/Transforms/InstCombine/ctpop-cttz.ll index 88675a4..d7cefe6 100644 --- a/llvm/test/Transforms/InstCombine/ctpop-cttz.ll +++ b/llvm/test/Transforms/InstCombine/ctpop-cttz.ll @@ -89,3 +89,50 @@ define i32 @ctpop2_multiuse(i32 %0) { %6 = add i32 %5, %4 ret i32 %6 } + +; PR51784 +; __builtin_popcount((i & -i) - 1) -> __builtin_cttz(i, false) +define i32 @ctpop3(i32 %0) { +; CHECK-LABEL: @ctpop3( +; CHECK-NEXT: [[TMP2:%.*]] = sub i32 0, [[TMP0:%.*]] +; CHECK-NEXT: [[TMP3:%.*]] = and i32 [[TMP2]], [[TMP0]] +; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP3]], -1 +; CHECK-NEXT: [[TMP5:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[TMP4]]), !range [[RNG0]] +; CHECK-NEXT: ret i32 [[TMP5]] +; + %2 = sub i32 0, %0 + %3 = and i32 %2, %0 + %4 = add i32 %3, -1 + %5 = tail call i32 @llvm.ctpop.i32(i32 %4) + ret i32 %5 +} + +define <2 x i32> @ctpop3v(<2 x i32> %0) { +; CHECK-LABEL: @ctpop3v( +; CHECK-NEXT: [[TMP2:%.*]] = sub <2 x i32> zeroinitializer, [[TMP0:%.*]] +; CHECK-NEXT: [[TMP3:%.*]] = and <2 x i32> [[TMP2]], [[TMP0]] +; CHECK-NEXT: [[TMP4:%.*]] = add <2 x i32> [[TMP3]], +; CHECK-NEXT: [[TMP5:%.*]] = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> [[TMP4]]) +; CHECK-NEXT: ret <2 x i32> [[TMP5]] +; + %2 = sub <2 x i32> zeroinitializer, %0 + %3 = and <2 x i32> %2, %0 + %4 = add <2 x i32> %3, + %5 = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %4) + ret <2 x i32> %5 +} + +define <2 x i32> @ctpop3v_undef(<2 x i32> %0) { +; CHECK-LABEL: @ctpop3v_undef( +; CHECK-NEXT: [[TMP2:%.*]] = sub <2 x i32> zeroinitializer, [[TMP0:%.*]] +; CHECK-NEXT: [[TMP3:%.*]] = and <2 x i32> [[TMP2]], [[TMP0]] +; CHECK-NEXT: [[TMP4:%.*]] = add <2 x i32> [[TMP3]], +; CHECK-NEXT: [[TMP5:%.*]] = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> [[TMP4]]) +; CHECK-NEXT: ret <2 x i32> [[TMP5]] +; + %2 = sub <2 x i32> zeroinitializer, %0 + %3 = and <2 x i32> %2, %0 + %4 = add <2 x i32> %3, + %5 = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %4) + ret <2 x i32> %5 +} -- 2.7.4