Created
January 20, 2022 22:05
-
-
Save andrewrk/54f93caf67cf0743c8b9f0face909b8b to your computer and use it in GitHub Desktop.
showing one example of improved LLVM IR for zig self hosted compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export fn entry() bool { | |
doTheTest() catch return false; | |
return true; | |
} | |
fn doTheTest() !void { | |
var x1: u8 = 42; | |
const t1 = .{ x1, 56, 54 }; | |
var arr1: [3]u8 = t1; | |
_ = arr1[0]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Function Attrs: nobuiltin nounwind | |
define internal fastcc i16 @doTheTest() unnamed_addr #1 { | |
Entry: | |
%result = alloca i16, align 2 | |
%x1 = alloca i8, align 1 | |
%t1 = alloca %"struct:24:25", align 1 | |
%0 = alloca [3 x i8], align 1 | |
%arr1 = alloca [3 x i8], align 1 | |
%1 = alloca [3 x i8], align 1 | |
%2 = alloca [3 x i8], align 1 | |
store i8 42, i8* %x1, align 1 | |
%3 = load i8, i8* %x1, align 1 | |
%4 = getelementptr inbounds %"struct:24:25", %"struct:24:25"* %t1, i32 0, i32 0 | |
store i8 %3, i8* %4, align 1 | |
%5 = getelementptr inbounds %"struct:24:25", %"struct:24:25"* %t1, i32 0, i32 0 | |
%6 = load i8, i8* %5, align 1 | |
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 0, i64 0 | |
store i8 %6, i8* %7, align 1 | |
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 0, i64 1 | |
store i8 56, i8* %8, align 1 | |
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 0, i64 2 | |
store i8 54, i8* %9, align 1 | |
%10 = getelementptr inbounds %"struct:24:25", %"struct:24:25"* %t1, i32 0, i32 0 | |
%11 = load i8, i8* %10, align 1 | |
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0 | |
store i8 %11, i8* %12, align 1 | |
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1 | |
store i8 56, i8* %13, align 1 | |
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2 | |
store i8 54, i8* %14, align 1 | |
%15 = bitcast [3 x i8]* %1 to i8* | |
%16 = bitcast [3 x i8]* %arr1 to i8* | |
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %16, i8* align 1 %15, i64 3, i1 false) | |
%17 = getelementptr inbounds %"struct:24:25", %"struct:24:25"* %t1, i32 0, i32 0 | |
%18 = load i8, i8* %17, align 1 | |
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0 | |
store i8 %18, i8* %19, align 1 | |
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1 | |
store i8 56, i8* %20, align 1 | |
%21 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2 | |
store i8 54, i8* %21, align 1 | |
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %arr1, i64 0, i64 0 | |
store i16 0, i16* %result, align 2 | |
ret i16 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%0 = type { i8 } | |
; Function Attrs: nounwind | |
define internal fastcc i16 @doTheTest() unnamed_addr #0 { | |
Entry: | |
%0 = alloca [3 x i8], align 1 | |
%1 = alloca i8, align 1 | |
store i8 42, i8* %1, align 1 | |
%2 = load i8, i8* %1, align 1 | |
%3 = insertvalue %0 undef, i8 %2, 0 | |
%4 = extractvalue %0 %3, 0 | |
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i32 0, i64 0 | |
store i8 %4, i8* %5, align 1 | |
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i32 0, i64 1 | |
store i8 56, i8* %6, align 1 | |
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i32 0, i64 2 | |
store i8 54, i8* %7, align 1 | |
ret i16 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment