Skip to content

LLVM pessimises vtable loads. #39992

Description

@Aatch

This code contains two offset calculations and two function pointer loads:

#![crate_type="lib"]

pub struct Wrapper<T: ?Sized> {
    x: usize,
    y: usize,
    t: T
}

pub trait Foo {
    fn foo(&self);
}

pub fn test(foo: &Wrapper<Foo>) {
    foo.t.foo();
    foo.t.foo();
}

Playpen

LLVM should be able to remove all but the first occurrences via common subexpression elimination, but for some reason it reloads from the vtable pointer each time. The only reasonable explanation I can think of is that LLVM assumes that the vtable pointer may alias some pointer that the called function manipulates.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions