1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -instcombine -S < %s | FileCheck %s 3 4define i32 @cttz_neg_value(i32 %x) { 5; CHECK-LABEL: @cttz_neg_value( 6; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false), !range !0 7; CHECK-NEXT: ret i32 [[B]] 8; 9 %a = sub i32 0, %x 10 %b = tail call i32 @llvm.cttz.i32(i32 %a) 11 ret i32 %b 12} 13 14define i32 @cttz_neg_value_multiuse(i32 %x) { 15; CHECK-LABEL: @cttz_neg_value_multiuse( 16; CHECK-NEXT: [[A:%.*]] = sub i32 0, [[X:%.*]] 17; CHECK-NEXT: call void @use(i32 [[A]]) 18; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[X]], i1 false), !range !0 19; CHECK-NEXT: ret i32 [[B]] 20; 21 %a = sub i32 0, %x 22 call void @use(i32 %a) 23 %b = tail call i32 @llvm.cttz.i32(i32 %a) 24 ret i32 %b 25} 26 27define i64 @cttz_neg_value_64(i64 %x) { 28; CHECK-LABEL: @cttz_neg_value_64( 29; CHECK-NEXT: [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X:%.*]], i1 true), !range !1 30; CHECK-NEXT: ret i64 [[B]] 31; 32 %a = sub i64 0, %x 33 %b = tail call i64 @llvm.cttz.i64(i64 %a, i1 true) 34 ret i64 %b 35} 36 37define i64 @cttz_neg_value2_64(i64 %x) { 38; CHECK-LABEL: @cttz_neg_value2_64( 39; CHECK-NEXT: [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X:%.*]], i1 false), !range !1 40; CHECK-NEXT: ret i64 [[B]] 41; 42 %a = sub i64 0, %x 43 %b = tail call i64 @llvm.cttz.i64(i64 %a, i1 false) 44 ret i64 %b 45} 46 47define <2 x i64> @cttz_neg_value_vec(<2 x i64> %x) { 48; CHECK-LABEL: @cttz_neg_value_vec( 49; CHECK-NEXT: [[B:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[X:%.*]], i1 false) 50; CHECK-NEXT: ret <2 x i64> [[B]] 51; 52 %a = sub <2 x i64> zeroinitializer, %x 53 %b = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %a) 54 ret <2 x i64> %b 55} 56 57; Negative tests 58 59define i32 @cttz_nonneg_value(i32 %x) { 60; CHECK-LABEL: @cttz_nonneg_value( 61; CHECK-NEXT: [[A:%.*]] = sub i32 1, [[X:%.*]] 62; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[A]], i1 false), !range !0 63; CHECK-NEXT: ret i32 [[B]] 64; 65 %a = sub i32 1, %x 66 %b = tail call i32 @llvm.cttz.i32(i32 %a) 67 ret i32 %b 68} 69 70define <2 x i64> @cttz_nonneg_value_vec(<2 x i64> %x) { 71; CHECK-LABEL: @cttz_nonneg_value_vec( 72; CHECK-NEXT: [[A:%.*]] = sub <2 x i64> <i64 1, i64 0>, [[X:%.*]] 73; CHECK-NEXT: [[B:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[A]], i1 false) 74; CHECK-NEXT: ret <2 x i64> [[B]] 75; 76 %a = sub <2 x i64> <i64 1, i64 0>, %x 77 %b = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %a) 78 ret <2 x i64> %b 79} 80 81declare void @use(i32 %a) 82declare i32 @llvm.cttz.i32(i32) 83declare i64 @llvm.cttz.i64(i64, i1) 84declare <2 x i64> @llvm.cttz.v2i64(<2 x i64>) 85