brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · cfcc767 Raw
151 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; Test that the strcmp library call simplifier works correctly.3; RUN: opt < %s -passes=instcombine -S | FileCheck %s4 5target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"6 7@hello = constant [6 x i8] c"hello\00"8@hell = constant [5 x i8] c"hell\00"9@bell = constant [5 x i8] c"bell\00"10@null = constant [1 x i8] zeroinitializer11 12declare i32 @strcmp(ptr, ptr)13 14; strcmp("", x) -> -*x15define arm_aapcscc i32 @test1(ptr %str2) {16; CHECK-LABEL: @test1(17; CHECK-NEXT:    [[STRCMPLOAD:%.*]] = load i8, ptr [[STR2:%.*]], align 118; CHECK-NEXT:    [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i3219; CHECK-NEXT:    [[TMP2:%.*]] = sub nsw i32 0, [[TMP1]]20; CHECK-NEXT:    ret i32 [[TMP2]]21;22 23  %temp1 = call arm_apcscc i32 @strcmp(ptr @null, ptr %str2)24  ret i32 %temp125 26}27 28; strcmp(x, "") -> *x29define arm_aapcscc i32 @test2(ptr %str1) {30; CHECK-LABEL: @test2(31; CHECK-NEXT:    [[STRCMPLOAD:%.*]] = load i8, ptr [[STR1:%.*]], align 132; CHECK-NEXT:    [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i3233; CHECK-NEXT:    ret i32 [[TMP1]]34;35 36  %temp1 = call arm_aapcscc i32 @strcmp(ptr %str1, ptr @null)37  ret i32 %temp138}39 40; strcmp(x, y)  -> cnst41define arm_aapcscc i32 @test3() {42; CHECK-LABEL: @test3(43; CHECK-NEXT:    ret i32 -144;45 46  %temp1 = call arm_aapcscc i32 @strcmp(ptr @hell, ptr @hello)47  ret i32 %temp148}49 50define arm_aapcscc i32 @test4() {51; CHECK-LABEL: @test4(52; CHECK-NEXT:    ret i32 153;54 55  %temp1 = call arm_aapcscc i32 @strcmp(ptr @hell, ptr @null)56  ret i32 %temp157}58 59; strcmp(x, y)   -> memcmp(x, y, <known length>)60; (This transform is rather difficult to trigger in a useful manner)61define arm_aapcscc i32 @test5(i1 %b) {62; CHECK-LABEL: @test5(63; CHECK-NEXT:    [[STR2:%.*]] = select i1 [[B:%.*]], ptr @hell, ptr @bell64; CHECK-NEXT:    [[MEMCMP:%.*]] = call i32 @memcmp(ptr noundef nonnull dereferenceable(5) @hello, ptr noundef nonnull dereferenceable(5) [[STR2]], i32 5)65; CHECK-NEXT:    ret i32 [[MEMCMP]]66;67 68  %str2 = select i1 %b, ptr @hell, ptr @bell69  %temp3 = call arm_aapcscc i32 @strcmp(ptr @hello, ptr %str2)70  ret i32 %temp371}72 73; strcmp(x,x)  -> 074define arm_aapcscc i32 @test6(ptr %str) {75; CHECK-LABEL: @test6(76; CHECK-NEXT:    ret i32 077;78 79  %temp1 = call arm_aapcscc i32 @strcmp(ptr %str, ptr %str)80  ret i32 %temp181}82 83; strcmp("", x) -> -*x84define arm_aapcs_vfpcc i32 @test1_vfp(ptr %str2) {85; CHECK-LABEL: @test1_vfp(86; CHECK-NEXT:    [[STRCMPLOAD:%.*]] = load i8, ptr [[STR2:%.*]], align 187; CHECK-NEXT:    [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i3288; CHECK-NEXT:    [[TMP2:%.*]] = sub nsw i32 0, [[TMP1]]89; CHECK-NEXT:    ret i32 [[TMP2]]90;91 92  %temp1 = call arm_aapcs_vfpcc i32 @strcmp(ptr @null, ptr %str2)93  ret i32 %temp194 95}96 97; strcmp(x, "") -> *x98define arm_aapcs_vfpcc i32 @test2_vfp(ptr %str1) {99; CHECK-LABEL: @test2_vfp(100; CHECK-NEXT:    [[STRCMPLOAD:%.*]] = load i8, ptr [[STR1:%.*]], align 1101; CHECK-NEXT:    [[TMP1:%.*]] = zext i8 [[STRCMPLOAD]] to i32102; CHECK-NEXT:    ret i32 [[TMP1]]103;104 105  %temp1 = call arm_aapcs_vfpcc i32 @strcmp(ptr %str1, ptr @null)106  ret i32 %temp1107}108 109; strcmp(x, y)  -> cnst110define arm_aapcs_vfpcc i32 @test3_vfp() {111; CHECK-LABEL: @test3_vfp(112; CHECK-NEXT:    ret i32 -1113;114 115  %temp1 = call arm_aapcs_vfpcc i32 @strcmp(ptr @hell, ptr @hello)116  ret i32 %temp1117}118 119define arm_aapcs_vfpcc i32 @test4_vfp() {120; CHECK-LABEL: @test4_vfp(121; CHECK-NEXT:    ret i32 1122;123 124  %temp1 = call arm_aapcs_vfpcc i32 @strcmp(ptr @hell, ptr @null)125  ret i32 %temp1126}127 128; strcmp(x, y)   -> memcmp(x, y, <known length>)129; (This transform is rather difficult to trigger in a useful manner)130define arm_aapcs_vfpcc i32 @test5_vfp(i1 %b) {131; CHECK-LABEL: @test5_vfp(132; CHECK-NEXT:    [[STR2:%.*]] = select i1 [[B:%.*]], ptr @hell, ptr @bell133; CHECK-NEXT:    [[MEMCMP:%.*]] = call i32 @memcmp(ptr noundef nonnull dereferenceable(5) @hello, ptr noundef nonnull dereferenceable(5) [[STR2]], i32 5)134; CHECK-NEXT:    ret i32 [[MEMCMP]]135;136 137  %str2 = select i1 %b, ptr @hell, ptr @bell138  %temp3 = call arm_aapcs_vfpcc i32 @strcmp(ptr @hello, ptr %str2)139  ret i32 %temp3140}141 142; strcmp(x,x)  -> 0143define arm_aapcs_vfpcc i32 @test6_vfp(ptr %str) {144; CHECK-LABEL: @test6_vfp(145; CHECK-NEXT:    ret i32 0146;147 148  %temp1 = call arm_aapcs_vfpcc i32 @strcmp(ptr %str, ptr %str)149  ret i32 %temp1150}151