aboutsummaryrefslogtreecommitdiff
path: root/test/Transforms/InstCombine/wcslen-2.ll
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2017-05-19 22:37:09 +0000
committerMatthias Braun <matze@braunis.de>2017-05-19 22:37:09 +0000
commit708626d601f5933f92eebff284996d81886faa28 (patch)
tree2b2a85f008d5b067378fc9a689e891e710925d91 /test/Transforms/InstCombine/wcslen-2.ll
parent60ecb7fde81665fe54e2ef278eed9fb25e9d8693 (diff)
SimplifyLibCalls: Optimize wcslen
Refactor the strlen optimization code to work for both strlen and wcslen. This especially helps with programs in the wild where people pass L"string"s to const std::wstring& function parameters and the wstring constructor gets inlined. This also fixes a lingerind API problem/bug in getConstantStringInfo() where zeroinitializers would always give you an empty string (without a length) back regardless of the actual length of the initializer which did not work well in the TrimAtNul==false causing the PR mentioned below. Note that the fixed getConstantStringInfo() needed fixes to SelectionDAG memcpy lowering and may lead to some cases for out-of-bounds zeroinitializer accesses not getting optimized anymore. So some code with UB may produce out of bound memory reads now instead of just producing zeros. The refactoring "accidentally" fixes http://llvm.org/PR32124 Differential Revision: https://reviews.llvm.org/D32839 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Transforms/InstCombine/wcslen-2.ll')
-rw-r--r--test/Transforms/InstCombine/wcslen-2.ll18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/wcslen-2.ll b/test/Transforms/InstCombine/wcslen-2.ll
new file mode 100644
index 00000000000..c1a70312a2b
--- /dev/null
+++ b/test/Transforms/InstCombine/wcslen-2.ll
@@ -0,0 +1,18 @@
+; Test that the wcslen library call simplifier works correctly.
+;
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+
+@hello = constant [6 x i32] [i32 104, i32 101, i32 108, i32 108, i32 111, i32 0]
+
+declare i64 @wcslen(i32*, i32)
+
+define i64 @test_no_simplify1() {
+; CHECK-LABEL: @test_no_simplify1(
+ %hello_p = getelementptr [6 x i32], [6 x i32]* @hello, i64 0, i64 0
+ %hello_l = call i64 @wcslen(i32* %hello_p, i32 187)
+; CHECK-NEXT: %hello_l = call i64 @wcslen
+ ret i64 %hello_l
+; CHECK-NEXT: ret i64 %hello_l
+}