mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
compiler: move OptimizeStringToBytes to transform package
Unfortunately, while doing this I found that it doesn't actually apply in any real-world programs (tested with `make smoketest`), apparently because nil pointer checking messes with the functionattrs pass. I hope to fix that after moving to LLVM 9, which has an optimization that makes nil pointer checking easier to implement.
This commit is contained in:
committed by
Ron Evans
parent
cea0d9f864
commit
65beddafe8
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64--linux"
|
||||
|
||||
@str = constant [6 x i8] c"foobar"
|
||||
|
||||
declare { i8*, i64, i64 } @runtime.stringToBytes(i8*, i64)
|
||||
|
||||
declare void @printSlice(i8* nocapture readonly, i64, i64)
|
||||
|
||||
declare void @writeToSlice(i8* nocapture, i64, i64)
|
||||
|
||||
; Test that runtime.stringToBytes can be fully optimized away.
|
||||
define void @testReadOnly() {
|
||||
entry:
|
||||
%0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6)
|
||||
%1 = extractvalue { i8*, i64, i64 } %0, 0
|
||||
%2 = extractvalue { i8*, i64, i64 } %0, 1
|
||||
%3 = extractvalue { i8*, i64, i64 } %0, 2
|
||||
call fastcc void @printSlice(i8* %1, i64 %2, i64 %3)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Test that even though the slice is written to, some values can be propagated.
|
||||
define void @testReadWrite() {
|
||||
entry:
|
||||
%0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6)
|
||||
%1 = extractvalue { i8*, i64, i64 } %0, 0
|
||||
%2 = extractvalue { i8*, i64, i64 } %0, 1
|
||||
%3 = extractvalue { i8*, i64, i64 } %0, 2
|
||||
call fastcc void @writeToSlice(i8* %1, i64 %2, i64 %3)
|
||||
ret void
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64--linux"
|
||||
|
||||
@str = constant [6 x i8] c"foobar"
|
||||
|
||||
declare { i8*, i64, i64 } @runtime.stringToBytes(i8*, i64)
|
||||
|
||||
declare void @printSlice(i8* nocapture readonly, i64, i64)
|
||||
|
||||
declare void @writeToSlice(i8* nocapture, i64, i64)
|
||||
|
||||
define void @testReadOnly() {
|
||||
entry:
|
||||
call fastcc void @printSlice(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6, i64 6)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @testReadWrite() {
|
||||
entry:
|
||||
%0 = call fastcc { i8*, i64, i64 } @runtime.stringToBytes(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i32 0, i32 0), i64 6)
|
||||
%1 = extractvalue { i8*, i64, i64 } %0, 0
|
||||
call fastcc void @writeToSlice(i8* %1, i64 6, i64 6)
|
||||
ret void
|
||||
}
|
||||
Reference in New Issue
Block a user