Issue 235236
Summary [SPARC] instruction selection ignores the optimization level; overwritten stores are dropped at -O0
Labels new issue
Assignees
Reporter shalseth
    SparcDAGToDAGISel is constructed without an optimization level (`SelectionDAGISel(tm)`), so it uses the default, and instruction selection on SPARC runs as it would at -O2 even with -O0. One visible effect is that a store immediately overwritten by another one is dropped, so the first assignment has no instruction and no line. c.ll:

```llvm
define void @g(ptr %p) {
  store i32 27, ptr %p
  store i32 99, ptr %p
  ret void
}
```

```
$ llc -O0 -mtriple=sparcv9 c.ll -o - | grep -E 'mov|st '
	mov	99, %o1
	st %o1, [%o0]
```

clang -O0 doesn't show it in practice, because the functions are `optnone` and SelectionDAGISel drops to -O0 for those on its own. With `-Xclang -disable-O0-optnone`, or with a frontend that doesn't add `optnone` such as rustc, it does:

```c
__attribute__((noinline)) void zzz(int *p) { __asm__ volatile("" : : "r"(p) : "memory"); }

int main(void)
{
	int c = 27;
	c = 99;
	zzz(&c);
	return c != 99;
}
```

```
$ clang -g -O0 -Xclang -disable-O0-optnone -S -o - dead.c
...
	.loc	0 6 4 prologue_end ! dead.c:6:4
	mov	99, %i0
	st %i0, [%fp+2035]
```

and `break dead.c:5` in gdb ends up on line 6. In the rustc debuginfo tests on sparc64 this is what breaks `function-arg-initialization.rs` (a `mut` argument that's reassigned first thing) and `basic-stepping.rs` (`let mut c = 27;` is skipped).

RISC-V and Mips pass the level through (`createRISCVISelDagLegacyPass(TM, getOptLevel())`). From a quick look Lanai, BPF, M68k and VE construct theirs the same way as SPARC, but I've only tested SPARC.

LLVM 23.1.4, clang 23.1.4, gdb 18.1, UltraSPARC T4-1, Linux sparc64.

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

Reply via email to