Index: llvm/test/Transforms/AggressiveInstCombine/strcmp.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/AggressiveInstCombine/strcmp.ll @@ -0,0 +1,92 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; TODO: Test that ... +; RUN: opt < %s -passes=aggressive-instcombine -S | FileCheck %s + +declare i32 @strcmp(ptr, ptr) + +@s1 = constant [2 x i8] c"0\00" +@s2 = constant [3 x i8] c"01\00", align 1 +@s3 = constant [4 x i8] c"012\00", align 1 +@s4 = constant [5 x i8] c"0123\00", align 1 + +; Expand strcmp(C, "x"). + +define i1 @expand_strcmp_s1_1(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s1_1( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s1) +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s1) + %cmp = icmp eq i32 %call, 0 + ret i1 %cmp +} + +define i32 @expand_strcmp_s1_2(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s1_2( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s1) +; CHECK-NEXT: ret i32 [[CALL]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s1) + ret i32 %call +} + +define i1 @expand_strcmp_s2_1(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s2_1( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s2) +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s2) + %cmp = icmp eq i32 %call, 0 + ret i1 %cmp +} + +define i32 @expand_strcmp_s2_2(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s2_2( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s2) +; CHECK-NEXT: ret i32 [[CALL]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s2) + ret i32 %call +} + +define i1 @expand_strcmp_s3_1(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s3_1( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s3) +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s3) + %cmp = icmp eq i32 %call, 0 + ret i1 %cmp +} + +define i32 @expand_strcmp_s3_2(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s3_2( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s3) +; CHECK-NEXT: ret i32 [[CALL]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s3) + ret i32 %call +} + +define i1 @expand_strcmp_s4_1(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s4_1( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s4) +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[CALL]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s4) + %cmp = icmp eq i32 %call, 0 + ret i1 %cmp +} + +define i32 @expand_strcmp_s4_2(ptr %C) { +; CHECK-LABEL: @expand_strcmp_s4_2( +; CHECK-NEXT: [[CALL:%.*]] = call i32 @strcmp(ptr [[C:%.*]], ptr noundef @s4) +; CHECK-NEXT: ret i32 [[CALL]] +; + %call = call i32 @strcmp(ptr %C, ptr noundef @s4) + ret i32 %call +}