diff options
| author | Matthias Braun <matze@braunis.de> | 2017-09-26 02:36:57 +0000 |
|---|---|---|
| committer | Matthias Braun <matze@braunis.de> | 2017-09-26 02:36:57 +0000 |
| commit | cc603ee3d563ca2ae27fb7bf439602a415a91268 (patch) | |
| tree | 873d87913405069b5f3754cdb59945e761753820 /llvm/test/Transforms | |
| parent | f2c83670f712c67b419fdb03f848e2cfb4e4c918 (diff) | |
| download | bcm5719-llvm-cc603ee3d563ca2ae27fb7bf439602a415a91268.tar.gz bcm5719-llvm-cc603ee3d563ca2ae27fb7bf439602a415a91268.zip | |
TargetLibraryInfo: Stop guessing wchar_t size
Usually the frontend communicates the size of wchar_t via metadata and
we can optimize wcslen (and possibly other calls in the future). In
cases without the wchar_size metadata we would previously try to guess
the correct size based on the target triple; however this is fragile to
keep up to date and may miss users manually changing the size via flags.
Better be safe and stop guessing and optimizing if the frontend didn't
communicate the size.
Differential Revision: https://reviews.llvm.org/D38106
llvm-svn: 314185
Diffstat (limited to 'llvm/test/Transforms')
| -rw-r--r-- | llvm/test/Transforms/InstCombine/wcslen-1.ll | 3 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/wcslen-2.ll | 3 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/wcslen-4.ll | 20 |
3 files changed, 26 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/wcslen-1.ll b/llvm/test/Transforms/InstCombine/wcslen-1.ll index cdde1bfbde4..22da95ef4ad 100644 --- a/llvm/test/Transforms/InstCombine/wcslen-1.ll +++ b/llvm/test/Transforms/InstCombine/wcslen-1.ll @@ -7,6 +7,9 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" declare i64 @wcslen(i32*) +!0 = !{i32 1, !"wchar_size", i32 4} +!llvm.module.flags = !{!0} + @hello = constant [6 x i32] [i32 104, i32 101, i32 108, i32 108, i32 111, i32 0] @longer = constant [7 x i32] [i32 108, i32 111, i32 110, i32 103, i32 101, i32 114, i32 0] @null = constant [1 x i32] zeroinitializer diff --git a/llvm/test/Transforms/InstCombine/wcslen-2.ll b/llvm/test/Transforms/InstCombine/wcslen-2.ll index c1a70312a2b..15f1fdbb1ad 100644 --- a/llvm/test/Transforms/InstCombine/wcslen-2.ll +++ b/llvm/test/Transforms/InstCombine/wcslen-2.ll @@ -4,6 +4,9 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +!0 = !{i32 1, !"wchar_size", i32 4} +!llvm.module.flags = !{!0} + @hello = constant [6 x i32] [i32 104, i32 101, i32 108, i32 108, i32 111, i32 0] declare i64 @wcslen(i32*, i32) diff --git a/llvm/test/Transforms/InstCombine/wcslen-4.ll b/llvm/test/Transforms/InstCombine/wcslen-4.ll new file mode 100644 index 00000000000..07832288965 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/wcslen-4.ll @@ -0,0 +1,20 @@ +; 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" + +; Without the wchar_size metadata we should see no optimization happening. + +@hello = constant [6 x i32] [i32 104, i32 101, i32 108, i32 108, i32 111, i32 0] + +declare i64 @wcslen(i32*) + +define i64 @test_no_simplify1() { +; CHECK-LABEL: @test_no_simplify1( +; CHECK-NEXT: %hello_l = call i64 @wcslen(i32* getelementptr inbounds ([6 x i32], [6 x i32]* @hello, i64 0, i64 0)) +; CHECK-NEXT: ret i64 %hello_l + %hello_p = getelementptr [6 x i32], [6 x i32]* @hello, i64 0, i64 0 + %hello_l = call i64 @wcslen(i32* %hello_p) + ret i64 %hello_l +} |

