-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
| Bugzilla Link | 42803 |
| Resolution | FIXED |
| Resolved on | Feb 24, 2020 15:17 |
| Version | 9.0 |
| OS | Linux |
| Blocks | #30613 |
| Attachments | llvm-ir |
| Reporter | LLVM Bugzilla Contributor |
| CC | @andrewrk,@topperc,@efriedma-quic,@RKSimon |
| Fixed by commit(s) | a5fa778 |
Extended Description
Using llvm 8 (Ubuntu Disco, 8.0.0-3 (tags/RELEASE_800/final)) The following zig program:
pub export fn start() void {
var a: [3]bool = []bool{ false, true, false};
var x2: @Vector(3, bool) = a;
if (x2[1] != true) unreachable;
}
const builtin = @import("builtin");
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
while (true) {}
}
compiles to this llvm-ir (full file included)
@0 = internal unnamed_addr constant [3 x i1] [i1 false, i1 true, i1 false], align 1
; Function Attrs: nobuiltin nounwind
define void @_start() #2 !dbg !136 {
Entry:
%a = alloca [3 x i1], align 1
%x2 = alloca <3 x i1>, align 4
%0 = bitcast [3 x i1]* %a to i8*, !dbg !147
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %0, i8* align 1 bitcast ([3 x i1]* @0 to i8*), i64 3, i1 false), !dbg !147
call void @llvm.dbg.declare(metadata [3 x i1]* %a, metadata !140, metadata !DIExpression()), !dbg !147
%1 = load [3 x i1], [3 x i1]* %a, !dbg !148
%vector_to_array = extractvalue [3 x i1] %1, 0, !dbg !148
%2 = insertelement <3 x i1> undef, i1 %vector_to_array, i32 0, !dbg !148
%vector_to_array1 = extractvalue [3 x i1] %1, 1, !dbg !148
%3 = insertelement <3 x i1> %2, i1 %vector_to_array1, i32 1, !dbg !148
%vector_to_array2 = extractvalue [3 x i1] %1, 2, !dbg !148
%4 = insertelement <3 x i1> %3, i1 %vector_to_array2, i32 2, !dbg !148
store <3 x i1> %4, <3 x i1>* %x2, align 4, !dbg !149
call void @llvm.dbg.declare(metadata <3 x i1>* %x2, metadata !145, metadata !DIExpression()), !dbg !149
%5 = load <3 x i1>, <3 x i1>* %x2, align 4, !dbg !150
%6 = extractelement <3 x i1> %5, i32 1, !dbg !150
%7 = icmp ne i1 %6, true, !dbg !151
br i1 %7, label %Then, label %Else, !dbg !152
Then: ; preds = %Entry
tail call fastcc void @panic(%"[]u8"* @2, %builtin.StackTrace* null), !dbg !153
unreachable, !dbg !153
Else: ; preds = %Entry
br label %EndIf, !dbg !152
EndIf: ; preds = %Else
ret void, !dbg !154
}
Which produces the following x86_64 (disassembled)
Dump of assembler code for function _start:
0x0000000000201010 <+0>: push %rbp
0x0000000000201011 <+1>: mov %rsp,%rbp
=> 0x0000000000201014 <+4>: sub $0x10,%rsp
0x0000000000201018 <+8>: mov -0xef8(%rip),%al # 0x200126 <__unnamed_1+2>
0x000000000020101e <+14>: mov %al,-0x2(%rbp)
0x0000000000201021 <+17>: mov -0xf04(%rip),%cx # 0x200124 <__unnamed_1>
0x0000000000201028 <+24>: mov %cx,-0x4(%rbp)
0x000000000020102c <+28>: mov -0x2(%rbp),%al
0x000000000020102f <+31>: mov -0x4(%rbp),%dl
0x0000000000201032 <+34>: mov -0x3(%rbp),%sil
0x0000000000201036 <+38>: add %sil,%sil
0x0000000000201039 <+41>: or %sil,%dl
0x000000000020103c <+44>: shl $0x2,%al
0x000000000020103f <+47>: or %al,%dl
0x0000000000201041 <+49>: and $0x7,%dl
0x0000000000201044 <+52>: mov %dl,-0xc(%rbp)
0x0000000000201047 <+55>: mov -0xc(%rbp),%al
0x000000000020104a <+58>: mov %al,-0x8(%rbp)
0x000000000020104d <+61>: mov -0x8(%rbp),%al
0x0000000000201050 <+64>: and $0x1,%al
0x0000000000201052 <+66>: neg %al
0x0000000000201054 <+68>: test $0x1,%al
0x0000000000201056 <+70>: jne 0x20106d <_start+93>
0x0000000000201058 <+72>: jmp 0x20105a <_start+74>
0x000000000020105a <+74>: xor %eax,%eax
0x000000000020105c <+76>: mov %eax,%esi
0x000000000020105e <+78>: movabs $0x200140,%rdi
0x0000000000201068 <+88>: callq 0x201000
0x000000000020106d <+93>: jmp 0x20106f <_start+95>
0x000000000020106f <+95>: add $0x10,%rsp
0x0000000000201073 <+99>: pop %rbp
0x0000000000201074 <+100>: retq