[PATCH] D107526: Clean up instcombine stpcpy test

Nathan Lanza via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 4 20:09:42 PDT 2021


lanza created this revision.
Herald added a subscriber: mstorsjo.
lanza requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Deduplicate some code and add an additional test to verify that the
sprintf->stpcpy optimization still works on android21 (which properly
supports it).

This follows up 58481663692b55 <https://reviews.llvm.org/rG58481663692b55ca03f8b41ccb660dcbcebffc49>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107526

Files:
  llvm/test/Transforms/InstCombine/sprintf-1.ll


Index: llvm/test/Transforms/InstCombine/sprintf-1.ll
===================================================================
--- llvm/test/Transforms/InstCombine/sprintf-1.ll
+++ llvm/test/Transforms/InstCombine/sprintf-1.ll
@@ -2,10 +2,11 @@
 ; Test that the sprintf library call simplifier works correctly.
 ;
 ; RUN: opt < %s -instcombine -S | FileCheck %s
-; RUN: opt < %s -mtriple xcore-xmos-elf -instcombine -S | FileCheck %s -check-prefixes=CHECK,CHECK-IPRINTF
+; RUN: opt < %s -mtriple xcore-xmos-elf -instcombine -S | FileCheck %s -check-prefixes=CHECK,CHECK-IPRINTF,WITHSTPCPY
 ; RUN: opt < %s -mtriple=i386-pc-windows-msvc -instcombine -S | FileCheck %s --check-prefixes=CHECK,WIN
-; RUN: opt < %s -mtriple=i386-mingw32 -instcombine -S | FileCheck %s --check-prefixes=CHECK,WIN
-; RUN: opt < %s -mtriple=armv7-none-linux-android16 -instcombine -S | FileCheck %s --check-prefixes=CHECK,ANDROID
+; RUN: opt < %s -mtriple=i386-mingw32 -instcombine -S | FileCheck %s --check-prefixes=CHECK,WIN,NOSTPCPY
+; RUN: opt < %s -mtriple=armv7-none-linux-android16 -instcombine -S | FileCheck %s --check-prefixes=CHECK,NOSTPCPY
+; RUN: opt < %s -mtriple=armv7-none-linux-android21 -instcombine -S | FileCheck %s --check-prefixes=CHECK,WITHSTPCPY
 
 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
 
@@ -97,24 +98,18 @@
 ; Check sprintf(dst, "%s", str) -> llvm.memcpy(dest, str, strlen(str) + 1, 1).
 
 define i32 @test_simplify7(i8* %dst, i8* %str) {
-; CHECK-IPRINTF-LABEL: @test_simplify7(
-; CHECK-IPRINTF-NEXT:    [[STPCPY:%.*]] = call i8* @stpcpy(i8* [[DST:%.*]], i8* [[STR:%.*]])
-; CHECK-IPRINTF-NEXT:    [[TMP1:%.*]] = ptrtoint i8* [[STPCPY]] to i32
-; CHECK-IPRINTF-NEXT:    [[TMP2:%.*]] = ptrtoint i8* [[DST]] to i32
-; CHECK-IPRINTF-NEXT:    [[TMP3:%.*]] = sub i32 [[TMP1]], [[TMP2]]
-; CHECK-IPRINTF-NEXT:    ret i32 [[TMP3]]
-;
-; WIN-LABEL: @test_simplify7(
-; WIN-NEXT:    [[STRLEN:%.*]] = call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]])
-; WIN-NEXT:    [[LENINC:%.*]] = add i32 [[STRLEN]], 1
-; WIN-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[DST:%.*]], i8* align 1 [[STR]], i32 [[LENINC]], i1 false)
-; WIN-NEXT:    ret i32 [[STRLEN]]
-;
-; ANDROID-LABEL: @test_simplify7(
-; ANDROID-NEXT:    [[STRLEN:%.*]] = call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]])
-; ANDROID-NEXT:    [[LENINC:%.*]] = add i32 [[STRLEN]], 1
-; ANDROID-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[DST:%.*]], i8* align 1 [[STR]], i32 [[LENINC]], i1 false)
-; ANDROID-NEXT:    ret i32 [[STRLEN]]
+; WITHSTPCPY-LABEL: @test_simplify7(
+; WITHSTPCPY-NEXT:    [[STPCPY:%.*]] = call i8* @stpcpy(i8* [[DST:%.*]], i8* [[STR:%.*]])
+; WITHSTPCPY-NEXT:    [[TMP1:%.*]] = ptrtoint i8* [[STPCPY]] to i32
+; WITHSTPCPY-NEXT:    [[TMP2:%.*]] = ptrtoint i8* [[DST]] to i32
+; WITHSTPCPY-NEXT:    [[TMP3:%.*]] = sub i32 [[TMP1]], [[TMP2]]
+; WITHSTPCPY-NEXT:    ret i32 [[TMP3]]
+;
+; NOSTPCPY-LABEL: @test_simplify7(
+; NOSTPCPY-NEXT:    [[STRLEN:%.*]] = call i32 @strlen(i8* noundef nonnull dereferenceable(1) [[STR:%.*]])
+; NOSTPCPY-NEXT:    [[LENINC:%.*]] = add i32 [[STRLEN]], 1
+; NOSTPCPY-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 [[DST:%.*]], i8* align 1 [[STR]], i32 [[LENINC]], i1 false)
+; NOSTPCPY-NEXT:    ret i32 [[STRLEN]]
 ;
   %fmt = getelementptr [3 x i8], [3 x i8]* @percent_s, i32 0, i32 0
   %r = call i32 (i8*, i8*, ...) @sprintf(i8* %dst, i8* %fmt, i8* %str)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107526.364332.patch
Type: text/x-patch
Size: 3537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210805/94dded2b/attachment.bin>


More information about the llvm-commits mailing list