Closed
Description
static A: bool = true;
fn main() {
if A {
std::io::println("hi");
}
}
Becomes with --opt-level=3
@_ZN1A20h08fe5d1e9d5f1e1deaaE = internal unnamed_addr constant i1 true
@str1231 = internal constant [3 x i8] c"hi"
; Function Attrs: uwtable
define internal void @_ZN4main20h2a63620ae66683eeraaE() unnamed_addr #0 {
entry-block:
%0 = alloca %str_slice, align 8
%1 = load i8* bitcast (i1* @_ZN1A20h08fe5d1e9d5f1e1deaaE to i8*), align 1, !range !0
%2 = icmp eq i8 %1, 0
br i1 %2, label %next-block, label %then-block-23-
then-block-23-: ; preds = %entry-block
%3 = bitcast %str_slice* %0 to i8*
call void @llvm.lifetime.start(i64 16, i8* %3)
%4 = getelementptr inbounds %str_slice* %0, i64 0, i32 0
store i8* getelementptr inbounds ([3 x i8]* @str1231, i64 0, i64 0), i8** %4, align 8
%5 = getelementptr inbounds %str_slice* %0, i64 0, i32 1
store i64 3, i64* %5, align 8
call void @_ZN2io5stdio7println20he27a305c3764dfd7P6lE(%str_slice* noalias nocapture dereferenceable(16) %0)
br label %next-block
next-block: ; preds = %entry-block, %then-block-23-
ret void
}
[...]
In particular %1
is loading from the A
static and branching on it. (Strangely enough, switching A
to false
does correctly eliminate the branch as dead.)