2020-03-22 03:30:22 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
|
|
; RUN: opt < %s -S -instcombine | FileCheck %s
|
|
|
|
|
|
|
|
declare i32 @llvm.ctpop.i32(i32)
|
|
|
|
declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>)
|
|
|
|
|
|
|
|
; PR43513
|
|
|
|
; __builtin_popcount(i | -i) -> 32 - __builtin_cttz(i, false)
|
|
|
|
define i32 @ctpop1(i32 %0) {
|
|
|
|
; CHECK-LABEL: @ctpop1(
|
2020-03-23 18:50:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0:%.*]], i1 false), !range !0
|
|
|
|
; CHECK-NEXT: ret i32 [[TMP2]]
|
2020-03-22 03:30:22 +08:00
|
|
|
;
|
|
|
|
%2 = sub i32 0, %0
|
2020-03-23 18:50:51 +08:00
|
|
|
%3 = or i32 %0, %2
|
2020-03-22 03:30:22 +08:00
|
|
|
%4 = tail call i32 @llvm.ctpop.i32(i32 %3)
|
|
|
|
%5 = sub i32 32, %4
|
|
|
|
ret i32 %5
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i32> @ctpop1v(<2 x i32> %0) {
|
|
|
|
; CHECK-LABEL: @ctpop1v(
|
2020-03-23 18:50:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[TMP0:%.*]], i1 false)
|
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = sub nsw <2 x i32> <i32 32, i32 32>, [[TMP2]]
|
|
|
|
; CHECK-NEXT: ret <2 x i32> [[TMP3]]
|
2020-03-22 03:30:22 +08:00
|
|
|
;
|
|
|
|
%2 = sub <2 x i32> zeroinitializer, %0
|
|
|
|
%3 = or <2 x i32> %2, %0
|
|
|
|
%4 = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %3)
|
2020-03-23 18:50:51 +08:00
|
|
|
ret <2 x i32> %4
|
2020-03-22 03:30:22 +08:00
|
|
|
}
|
|
|
|
|
2020-03-23 22:24:05 +08:00
|
|
|
define i32 @ctpop1_multiuse(i32 %0) {
|
|
|
|
; CHECK-LABEL: @ctpop1_multiuse(
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = sub i32 0, [[TMP0:%.*]]
|
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = or i32 [[TMP2]], [[TMP0]]
|
|
|
|
; CHECK-NEXT: [[TMP4:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[TMP3]]), !range !0
|
|
|
|
; CHECK-NEXT: [[TMP5:%.*]] = sub nuw nsw i32 32, [[TMP4]]
|
|
|
|
; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[TMP5]], [[TMP3]]
|
|
|
|
; CHECK-NEXT: ret i32 [[TMP6]]
|
|
|
|
;
|
|
|
|
%2 = sub i32 0, %0
|
|
|
|
%3 = or i32 %0, %2
|
|
|
|
%4 = tail call i32 @llvm.ctpop.i32(i32 %3)
|
|
|
|
%5 = sub i32 32, %4
|
|
|
|
%6 = add i32 %5, %3
|
|
|
|
ret i32 %6
|
|
|
|
}
|
|
|
|
|
2020-03-22 03:30:22 +08:00
|
|
|
; PR43513
|
|
|
|
; __builtin_popcount(~i & (i-1)) -> __builtin_cttz(i, false)
|
|
|
|
define i32 @ctpop2(i32 %0) {
|
|
|
|
; CHECK-LABEL: @ctpop2(
|
2020-03-23 18:50:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0:%.*]], i1 false), !range !0
|
|
|
|
; CHECK-NEXT: ret i32 [[TMP2]]
|
2020-03-22 03:30:22 +08:00
|
|
|
;
|
|
|
|
%2 = xor i32 %0, -1
|
2020-03-23 18:50:51 +08:00
|
|
|
%3 = sub i32 %0, 1
|
2020-03-22 03:30:22 +08:00
|
|
|
%4 = and i32 %3, %2
|
|
|
|
%5 = tail call i32 @llvm.ctpop.i32(i32 %4)
|
|
|
|
ret i32 %5
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i32> @ctpop2v(<2 x i32> %0) {
|
|
|
|
; CHECK-LABEL: @ctpop2v(
|
2020-03-23 18:50:51 +08:00
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> [[TMP0:%.*]], i1 false)
|
|
|
|
; CHECK-NEXT: ret <2 x i32> [[TMP2]]
|
2020-03-22 03:30:22 +08:00
|
|
|
;
|
|
|
|
%2 = xor <2 x i32> %0, <i32 -1, i32 -1>
|
|
|
|
%3 = add <2 x i32> %0, <i32 -1, i32 -1>
|
2020-03-23 18:50:51 +08:00
|
|
|
%4 = and <2 x i32> %2, %3
|
2020-03-22 03:30:22 +08:00
|
|
|
%5 = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %4)
|
|
|
|
ret <2 x i32> %5
|
|
|
|
}
|
2020-03-23 22:24:05 +08:00
|
|
|
|
|
|
|
define i32 @ctpop2_multiuse(i32 %0) {
|
|
|
|
; CHECK-LABEL: @ctpop2_multiuse(
|
|
|
|
; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP0:%.*]], -1
|
|
|
|
; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[TMP0]], -1
|
|
|
|
; CHECK-NEXT: [[TMP4:%.*]] = and i32 [[TMP3]], [[TMP2]]
|
2020-03-24 01:56:07 +08:00
|
|
|
; CHECK-NEXT: [[TMP5:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 false), !range !0
|
2020-03-23 22:24:05 +08:00
|
|
|
; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[TMP5]], [[TMP4]]
|
|
|
|
; CHECK-NEXT: ret i32 [[TMP6]]
|
|
|
|
;
|
|
|
|
%2 = xor i32 %0, -1
|
|
|
|
%3 = sub i32 %0, 1
|
|
|
|
%4 = and i32 %3, %2
|
|
|
|
%5 = tail call i32 @llvm.ctpop.i32(i32 %4)
|
|
|
|
%6 = add i32 %5, %4
|
|
|
|
ret i32 %6
|
|
|
|
}
|