Issue 58128
Summary Load unnecessarily happens before malloc
Labels new issue
Assignees
Reporter jrmuizel
    The following code will be compiled with the load of `next` happening before the call to `malloc`. This generates worse code than if the load is delayed until after the call to `malloc`.

```c
struct Foo {
    Foo* next;
};
void ctx_push(Foo* f) {
    Foo tmp = { f->next };
    Foo *n = (Foo*)malloc(sizeof(Foo));
    *n = tmp;
    f->next = n;
}
```

Manually moving the load in this example improves the generated code:
```c
struct Foo {
    Foo* next;
};

void ctx_push(Foo* f) {
    Foo *n = (Foo*)malloc(sizeof(Foo));
    Foo tmp = { f->next };
    *n = tmp;
    f->next = n;
}
```

https://gcc.godbolt.org/z/jKvWEfvdc
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to