; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+declare void @use(i64)
+declare void @use_i32(i32)
+
+declare i32 @llvm.cttz.i32(i32, i1 immarg)
+declare <2 x i8> @llvm.cttz.v2i8(<2 x i8>, i1 immarg)
+
define <4 x i32> @lshr_non_splat_vector(<4 x i32> %A) {
; CHECK-LABEL: @lshr_non_splat_vector(
; CHECK-NEXT: [[B:%.*]] = lshr <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
;; (A >> 8) << 8 === A & -256
define i32 @test12(i32 %A) {
; CHECK-LABEL: @test12(
-; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -256
-; CHECK-NEXT: ret i32 [[TMP1]]
+; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], -256
+; CHECK-NEXT: ret i32 [[C]]
;
%B = ashr i32 %A, 8
%C = shl i32 %B, 8
ret i32 %D
}
-
define i1 @test27(i32 %x) nounwind {
; CHECK-LABEL: @test27(
; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 8
ret i64 %shl
}
-declare void @use(i64)
-
define i64 @shl_zext_extra_use(i32 %t) {
; CHECK-LABEL: @shl_zext_extra_use(
; CHECK-NEXT: [[AND:%.*]] = and i32 [[T:%.*]], 16777215
ret i64 %shl
}
-
define <2 x i64> @shl_zext_splat_vec(<2 x i32> %t) {
; CHECK-LABEL: @shl_zext_splat_vec(
; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[T:%.*]], <i32 8, i32 8>
ret i64 %shl
}
-declare void @use_i32(i32)
-
define i64 @shl_zext_mul_extra_use2(i32 %t) {
; CHECK-LABEL: @shl_zext_mul_extra_use2(
; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
%r = ashr i32 %d, 31
ret i32 %r
}
+
+define i32 @shl1_cttz(i32 %x) {
+; CHECK-LABEL: @shl1_cttz(
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true), !range [[RNG0:![0-9]+]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[TZ]]
+; CHECK-NEXT: ret i32 [[SHL]]
+;
+ %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
+ %shl = shl i32 1, %tz
+ ret i32 %shl
+}
+
+define <2 x i8> @shl1_cttz_vec(<2 x i8> %x) {
+; CHECK-LABEL: @shl1_cttz_vec(
+; CHECK-NEXT: [[TZ:%.*]] = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> [[X:%.*]], i1 false)
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw <2 x i8> <i8 1, i8 1>, [[TZ]]
+; CHECK-NEXT: ret <2 x i8> [[SHL]]
+;
+ %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
+ %shl = shl <2 x i8> <i8 1, i8 1>, %tz
+ ret <2 x i8> %shl
+}
+
+define <2 x i8> @shl1_cttz_vec_poison(<2 x i8> %x) {
+; CHECK-LABEL: @shl1_cttz_vec_poison(
+; CHECK-NEXT: [[TZ:%.*]] = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> [[X:%.*]], i1 false)
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw <2 x i8> <i8 1, i8 poison>, [[TZ]]
+; CHECK-NEXT: ret <2 x i8> [[SHL]]
+;
+ %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
+ %shl = shl <2 x i8> <i8 1, i8 poison>, %tz
+ ret <2 x i8> %shl
+}
+
+define i32 @shl1_cttz_extra_use(i32 %x) {
+; CHECK-LABEL: @shl1_cttz_extra_use(
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false), !range [[RNG0]]
+; CHECK-NEXT: call void @use_i32(i32 [[TZ]])
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[TZ]]
+; CHECK-NEXT: ret i32 [[SHL]]
+;
+ %tz = call i32 @llvm.cttz.i32(i32 %x, i1 false)
+ call void @use_i32(i32 %tz)
+ %shl = shl i32 1, %tz
+ ret i32 %shl
+}
+
+define i32 @shl2_cttz(i32 %x) {
+; CHECK-LABEL: @shl2_cttz(
+; CHECK-NEXT: [[TZ:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true), !range [[RNG0]]
+; CHECK-NEXT: [[SHL:%.*]] = shl i32 2, [[TZ]]
+; CHECK-NEXT: ret i32 [[SHL]]
+;
+ %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
+ %shl = shl i32 2, %tz
+ ret i32 %shl
+}