Skip to content

Instantly share code, notes, and snippets.

@nickdesaulniers
Created September 11, 2023 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdesaulniers/1c7b962222639e54c3339b63b572b166 to your computer and use it in GitHub Desktop.
Save nickdesaulniers/1c7b962222639e54c3339b63b572b166 to your computer and use it in GitHub Desktop.
struct foo {
int x;
};
// Returns a reference to the minimum foo.
foo &&min(foo &&a, foo &&b);
void consume (foo&&);
void bar () {
consume(min(foo{0}, foo{1}));
}
define dso_local void @_Z3barv() #0 {
entry:
%ref.tmp = alloca %struct.foo, align 4
%ref.tmp1 = alloca %struct.foo, align 4
call void @llvm.lifetime.start.p0(i64 4, ptr %ref.tmp) #3
%x = getelementptr inbounds %struct.foo, ptr %ref.tmp, i32 0, i32 0
store i32 0, ptr %x, align 4, !tbaa !5
call void @llvm.lifetime.start.p0(i64 4, ptr %ref.tmp1) #3
%x2 = getelementptr inbounds %struct.foo, ptr %ref.tmp1, i32 0, i32 0
store i32 1, ptr %x2, align 4, !tbaa !5
%call = call noundef nonnull align 4 dereferenceable(4) ptr @_Z3minO3fooS0_(ptr noundef nonnull align 4 dereferenceable(4) %ref.tmp, ptr noundef nonnull align 4 dereferenceable(4) %ref.tmp1)
call void @_Z7consumeO3foo(ptr noundef nonnull align 4 dereferenceable(4) %call)
call void @llvm.lifetime.end.p0(i64 4, ptr %ref.tmp1) #3
call void @llvm.lifetime.end.p0(i64 4, ptr %ref.tmp) #3
ret void
}
struct foo {
int x;
};
// Returns a reference to the minimum foo.
const foo &min(const foo &a, const foo &b);
void consume (const foo&);
void bar () {
consume(min(foo{0}, foo{1}));
}
define dso_local void @_Z3barv() #0 {
entry:
%ref.tmp = alloca %struct.foo, align 4
%ref.tmp1 = alloca %struct.foo, align 4
call void @llvm.lifetime.start.p0(i64 4, ptr %ref.tmp) #3
%x = getelementptr inbounds %struct.foo, ptr %ref.tmp, i32 0, i32 0
store i32 0, ptr %x, align 4, !tbaa !5
call void @llvm.lifetime.start.p0(i64 4, ptr %ref.tmp1) #3
%x2 = getelementptr inbounds %struct.foo, ptr %ref.tmp1, i32 0, i32 0
store i32 1, ptr %x2, align 4, !tbaa !5
%call = call noundef nonnull align 4 dereferenceable(4) ptr @_Z3minRK3fooS1_(ptr noundef nonnull align 4 dereferenceable(4) %ref.tmp, ptr noundef nonnull align 4 dereferenceable(4) %ref.tmp1)
call void @_Z7consumeRK3foo(ptr noundef nonnull align 4 dereferenceable(4) %call)
call void @llvm.lifetime.end.p0(i64 4, ptr %ref.tmp1) #3
call void @llvm.lifetime.end.p0(i64 4, ptr %ref.tmp) #3
ret void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment