forked from OSchip/llvm-project
Clean up instcombine stpcpy test
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 5848166369
.
Differential Revision: https://reviews.llvm.org/D107526
This commit is contained in:
parent
11565320fd
commit
7dd29ad4ae
|
@ -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 @@ define void @test_simplify6(i8* %dst) {
|
|||
; 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]]
|
||||
; 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]]
|
||||
;
|
||||
; 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]]
|
||||
; 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)
|
||||
|
|
Loading…
Reference in New Issue