349 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S < %s -mtriple=unknown -passes=instcombine | FileCheck -check-prefixes=CHECK,CHECK32 %s3; RUN: opt -S < %s -mtriple=msp430 -passes=instcombine | FileCheck -check-prefixes=CHECK,CHECK16 %s4target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"5 6@G = constant [3 x i8] c"%s\00" ; <ptr> [#uses=1]7 8; A 16-bit compatible sprintf is not recognized as the standard library9; function on 32-bit targets.10declare i16 @sprintf(ptr, ptr, ...)11 12define void @foo(ptr %P, ptr %X) {13; CHECK32-LABEL: @foo(14; CHECK32-NEXT: [[TMP1:%.*]] = call i16 (ptr, ptr, ...) @sprintf(ptr [[P:%.*]], ptr nonnull @G, ptr [[X:%.*]])15; CHECK32-NEXT: ret void16;17; CHECK16-LABEL: @foo(18; CHECK16-NEXT: [[STRCPY:%.*]] = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) [[P:%.*]], ptr noundef nonnull dereferenceable(1) [[X:%.*]])19; CHECK16-NEXT: ret void20;21 call i16 (ptr, ptr, ...) @sprintf(ptr %P, ptr @G, ptr %X ) ; <i32>:1 [#uses=0]22 ret void23}24 25; PR130726@str = internal constant [5 x i8] c"foog\00"27@str1 = internal constant [8 x i8] c"blahhh!\00"28@str2 = internal constant [5 x i8] c"Ponk\00"29 30define ptr @test1() {31; CHECK32-LABEL: @test1(32; CHECK32-NEXT: [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds nuw (i8, ptr @str, i32 2), i16 103)33; CHECK32-NEXT: ret ptr [[TMP3]]34;35; CHECK16-LABEL: @test1(36; CHECK16-NEXT: ret ptr getelementptr inbounds nuw (i8, ptr @str, i32 3)37;38 %tmp3 = tail call ptr @strchr( ptr getelementptr ([5 x i8], ptr @str, i32 0, i16 2), i16 103 ) ; <ptr> [#uses=1]39 ret ptr %tmp340}41 42; A 16-bit compatible strchr is not recognized as the standard library43; function on 32-bit targets.44declare ptr @strchr(ptr, i16)45 46define ptr @test2() {47; CHECK32-LABEL: @test2(48; CHECK32-NEXT: [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds nuw (i8, ptr @str1, i32 2), i16 0)49; CHECK32-NEXT: ret ptr [[TMP3]]50;51; CHECK16-LABEL: @test2(52; CHECK16-NEXT: ret ptr getelementptr inbounds nuw (i8, ptr @str1, i32 7)53;54 %tmp3 = tail call ptr @strchr( ptr getelementptr ([8 x i8], ptr @str1, i32 0, i32 2), i16 0 ) ; <ptr> [#uses=1]55 ret ptr %tmp356}57 58define ptr @test3() {59; CHECK32-LABEL: @test3(60; CHECK32-NEXT: entry:61; CHECK32-NEXT: [[TMP3:%.*]] = tail call ptr @strchr(ptr nonnull getelementptr inbounds nuw (i8, ptr @str2, i32 1), i16 80)62; CHECK32-NEXT: ret ptr [[TMP3]]63;64; CHECK16-LABEL: @test3(65; CHECK16-NEXT: entry:66; CHECK16-NEXT: ret ptr null67;68entry:69 %tmp3 = tail call ptr @strchr( ptr getelementptr ([5 x i8], ptr @str2, i32 0, i32 1), i16 80 ) ; <ptr> [#uses=1]70 ret ptr %tmp371 72}73 74@_2E_str = external constant [5 x i8] ; <ptr> [#uses=1]75 76; A 16-bit compatible memcmp is not recognized as the standard library77; function on 32-bit targets.78declare i16 @memcmp(ptr, ptr, i16) nounwind readonly79 80define i1 @PR2341(ptr %start_addr) {81; CHECK-LABEL: @PR2341(82; CHECK-NEXT: entry:83; CHECK-NEXT: [[TMP4:%.*]] = load ptr, ptr [[START_ADDR:%.*]], align 484; CHECK-NEXT: [[TMP5:%.*]] = call i16 @memcmp(ptr [[TMP4]], ptr nonnull @_2E_str, i16 4) #[[ATTR0:[0-9]+]]85; CHECK-NEXT: [[TMP6:%.*]] = icmp eq i16 [[TMP5]], 086; CHECK-NEXT: ret i1 [[TMP6]]87;88entry:89 %tmp4 = load ptr, ptr %start_addr, align 4 ; <ptr> [#uses=1]90 %tmp5 = call i16 @memcmp( ptr %tmp4, ptr @_2E_str, i16 4 ) nounwind readonly ; <i32> [#uses=1]91 %tmp6 = icmp eq i16 %tmp5, 0 ; <i1> [#uses=1]92 ret i1 %tmp693 94}95 96define i16 @PR4284() nounwind {97; CHECK-LABEL: @PR4284(98; CHECK-NEXT: entry:99; CHECK-NEXT: [[C0:%.*]] = alloca i8, align 1100; CHECK-NEXT: [[C2:%.*]] = alloca i8, align 1101; CHECK-NEXT: store i8 64, ptr [[C0]], align 1102; CHECK-NEXT: store i8 -127, ptr [[C2]], align 1103; CHECK-NEXT: [[CALL:%.*]] = call i16 @memcmp(ptr nonnull [[C0]], ptr nonnull [[C2]], i16 1)104; CHECK-NEXT: ret i16 [[CALL]]105;106entry:107 %c0 = alloca i8, align 1 ; <ptr> [#uses=2]108 %c2 = alloca i8, align 1 ; <ptr> [#uses=2]109 store i8 64, ptr %c0110 store i8 -127, ptr %c2111 %call = call i16 @memcmp(ptr %c0, ptr %c2, i16 1) ; <i32> [#uses=1]112 ret i16 %call113 114}115 116%struct.__sFILE = type { ptr, i32, i32, i16, i16, %struct.__sbuf, i32, ptr, ptr, ptr, ptr, ptr, %struct.__sbuf, ptr, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64, ptr, ptr, i32, i32, %union.anon }117%struct.__sbuf = type { ptr, i32, [4 x i8] }118%struct.pthread = type opaque119%struct.pthread_mutex = type opaque120%union.anon = type { i64, [120 x i8] }121@.str13 = external constant [2 x i8] ; <ptr> [#uses=1]122@.str14 = external constant [2 x i8] ; <ptr> [#uses=1]123 124define i32 @PR4641(i32 %argc, ptr %argv, i1 %c1, ptr %ptr) nounwind {125; CHECK-LABEL: @PR4641(126; CHECK-NEXT: entry:127; CHECK-NEXT: call void @exit(i16 0) #[[ATTR1:[0-9]+]]128; CHECK-NEXT: [[COND392:%.*]] = select i1 [[C1:%.*]], ptr @.str13, ptr @.str14129; CHECK-NEXT: [[CALL393:%.*]] = call ptr @fopen(ptr [[PTR:%.*]], ptr nonnull [[COND392]]) #[[ATTR1]]130; CHECK-NEXT: unreachable131;132entry:133 call void @exit(i16 0) nounwind134 %cond392 = select i1 %c1, ptr @.str13, ptr @.str14 ; <ptr> [#uses=1]135 %call393 = call ptr @fopen(ptr %ptr, ptr %cond392) nounwind ; <ptr> [#uses=0]136 unreachable137}138 139declare ptr @fopen(ptr, ptr)140 141; A 16-bit compatible exit is not recognized as the standard library142; function on 32-bit targets.143declare void @exit(i16)144 145define i32 @PR4645(i1 %c1) {146; CHECK32-LABEL: @PR4645(147; CHECK32-NEXT: entry:148; CHECK32-NEXT: br label [[IF_THEN:%.*]]149; CHECK32: lor.lhs.false:150; CHECK32-NEXT: br i1 [[C1:%.*]], label [[IF_THEN]], label [[FOR_COND:%.*]]151; CHECK32: if.then:152; CHECK32-NEXT: call void @exit(i16 1)153; CHECK32-NEXT: br label [[FOR_COND]]154; CHECK32: for.cond:155; CHECK32-NEXT: unreachable156; CHECK32: for.end:157; CHECK32-NEXT: br label [[FOR_COND]]158;159; CHECK16-LABEL: @PR4645(160; CHECK16-NEXT: entry:161; CHECK16-NEXT: br label [[IF_THEN:%.*]]162; CHECK16: lor.lhs.false:163; CHECK16-NEXT: br i1 [[C1:%.*]], label [[IF_THEN]], label [[FOR_COND:%.*]]164; CHECK16: if.then:165; CHECK16-NEXT: call void @exit(i16 1) #[[ATTR6:[0-9]+]]166; CHECK16-NEXT: br label [[FOR_COND]]167; CHECK16: for.cond:168; CHECK16-NEXT: unreachable169; CHECK16: for.end:170; CHECK16-NEXT: br label [[FOR_COND]]171;172entry:173 br label %if.then174 175lor.lhs.false: ; preds = %while.body176 br i1 %c1, label %if.then, label %for.cond177 178if.then: ; preds = %lor.lhs.false, %while.body179 call void @exit(i16 1)180 br label %for.cond181 182for.cond: ; preds = %for.end, %if.then, %lor.lhs.false183 %j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ] ; <i32> [#uses=1]184 unreachable185 186for.end: ; preds = %for.cond20187 %inc47 = add i32 %j.0, 1 ; <i32> [#uses=1]188 br label %for.cond189}190 191@h = constant [2 x i8] c"h\00" ; <ptr> [#uses=1]192@hel = constant [4 x i8] c"hel\00" ; <ptr> [#uses=1]193@hello_u = constant [8 x i8] c"hello_u\00" ; <ptr> [#uses=1]194 195define i32 @MemCpy() {196; CHECK-LABEL: @MemCpy(197; CHECK-NEXT: ret i32 0198;199 %target = alloca [1024 x i8]200 call void @llvm.memcpy.p0.p0.i32(ptr align 2 %target, ptr align 2 @h, i16 2, i1 false)201 call void @llvm.memcpy.p0.p0.i32(ptr align 4 %target, ptr align 4 @hel, i16 4, i1 false)202 call void @llvm.memcpy.p0.p0.i32(ptr align 8 %target, ptr align 8 @hello_u, i16 8, i1 false)203 ret i32 0204 205}206 207declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i16, i1)208 209; A 16-bit compatible strcmp is not recognized as the standard library210; function on 32-bit targets.211declare i16 @strcmp(ptr, ptr) #0212 213define void @test9(ptr %x) {214; CHECK32-LABEL: @test9(215; CHECK32-NEXT: [[Y:%.*]] = call i16 @strcmp(ptr [[X:%.*]], ptr [[X]]) #[[ATTR6:[0-9]+]]216; CHECK32-NEXT: ret void217;218; CHECK16-LABEL: @test9(219; CHECK16-NEXT: ret void220;221 %y = call i16 @strcmp(ptr %x, ptr %x) #1222 ret void223}224 225; PR30484 - https://llvm.org/bugs/show_bug.cgi?id=30484226; These aren't the library functions you're looking for...227 228declare i32 @isdigit(i8)229declare i32 @isascii(i8)230declare i32 @toascii(i8)231 232define i32 @fake_isdigit(i8 %x) {233; CHECK-LABEL: @fake_isdigit(234; CHECK-NEXT: [[Y:%.*]] = call i32 @isdigit(i8 [[X:%.*]])235; CHECK-NEXT: ret i32 [[Y]]236;237 %y = call i32 @isdigit(i8 %x)238 ret i32 %y239}240 241define i32 @fake_isascii(i8 %x) {242; CHECK-LABEL: @fake_isascii(243; CHECK-NEXT: [[Y:%.*]] = call i32 @isascii(i8 [[X:%.*]])244; CHECK-NEXT: ret i32 [[Y]]245;246 %y = call i32 @isascii(i8 %x)247 ret i32 %y248}249 250define i32 @fake_toascii(i8 %x) {251; CHECK-LABEL: @fake_toascii(252; CHECK-NEXT: [[Y:%.*]] = call i32 @toascii(i8 [[X:%.*]])253; CHECK-NEXT: ret i32 [[Y]]254;255 %y = call i32 @toascii(i8 %x)256 ret i32 %y257}258 259declare double @pow(double, double)260declare double @exp2(double)261 262; check to make sure only the correct libcall attributes are used263define double @fake_exp2(double %x) {264; CHECK-LABEL: @fake_exp2(265; CHECK-NEXT: [[EXP2:%.*]] = call double @exp2(double [[X:%.*]])266; CHECK-NEXT: ret double [[EXP2]]267;268 269 %y = call inreg double @pow(double inreg 2.0, double inreg %x)270 ret double %y271}272define double @fake_ldexp(i32 %x) {273; CHECK32-LABEL: @fake_ldexp(274; CHECK32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[X:%.*]])275; CHECK32-NEXT: ret double [[LDEXP]]276;277; CHECK16-LABEL: @fake_ldexp(278; CHECK16-NEXT: [[Y:%.*]] = sitofp i32 [[X:%.*]] to double279; CHECK16-NEXT: [[Z:%.*]] = call inreg double @exp2(double [[Y]])280; CHECK16-NEXT: ret double [[Z]]281;282 283 284 %y = sitofp i32 %x to double285 %z = call inreg double @exp2(double %y)286 ret double %z287}288define double @fake_ldexp_16(i16 %x) {289; CHECK32-LABEL: @fake_ldexp_16(290; CHECK32-NEXT: [[TMP1:%.*]] = sext i16 [[X:%.*]] to i32291; CHECK32-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i32 [[TMP1]])292; CHECK32-NEXT: ret double [[LDEXP]]293;294; CHECK16-LABEL: @fake_ldexp_16(295; CHECK16-NEXT: [[LDEXP:%.*]] = call double @ldexp(double 1.000000e+00, i16 [[X:%.*]])296; CHECK16-NEXT: ret double [[LDEXP]]297;298 299 300 %y = sitofp i16 %x to double301 %z = call inreg double @exp2(double %y)302 ret double %z303}304 305; PR50885 - this would crash in ValueTracking.306 307; A 16-bit compatible snprintf is not recognized as the standard library308; function on 32-bit targets.309declare i16 @snprintf(ptr, double, ptr)310 311define i16 @fake_snprintf(i32 %buf, double %len, ptr %str, ptr %ptr) {312; CHECK-LABEL: @fake_snprintf(313; CHECK-NEXT: [[CALL:%.*]] = call i16 @snprintf(ptr [[PTR:%.*]], double [[LEN:%.*]], ptr [[STR:%.*]])314; CHECK-NEXT: ret i16 [[CALL]]315;316 %call = call i16 @snprintf(ptr %ptr, double %len, ptr %str)317 ret i16 %call318}319 320; Wrong return type for the real strlen.321; https://llvm.org/PR50836322 323define i4 @strlen(ptr %s) {324; CHECK-LABEL: @strlen(325; CHECK-NEXT: [[R:%.*]] = call i4 @strlen(ptr [[S:%.*]])326; CHECK-NEXT: ret i4 0327;328 %r = call i4 @strlen(ptr %s)329 ret i4 0330}331 332; Test emission of stpncpy, including call attributes.333@a = dso_local global [4 x i8] c"123\00"334@b = dso_local global [5 x i8] zeroinitializer335declare ptr @__stpncpy_chk(ptr noundef, ptr noundef, i32 noundef, i32 noundef)336define signext i32 @emit_stpncpy() {337; CHECK-LABEL: @emit_stpncpy(338; CHECK-NEXT: [[STPNCPY:%.*]] = call ptr @stpncpy(ptr noundef nonnull dereferenceable(1) @b, ptr noundef nonnull dereferenceable(1) @a, i32 2)339; CHECK-NEXT: ret i32 0340;341 %call = call ptr @__stpncpy_chk(ptr noundef @b,342 ptr noundef @a,343 i32 noundef 2, i32 noundef 5)344 ret i32 0345}346 347attributes #0 = { nobuiltin }348attributes #1 = { builtin }349