https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70018
Jan Hubicka <hubicka at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |hubicka at gcc dot gnu.org --- Comment #11 from Jan Hubicka <hubicka at gcc dot gnu.org> --- For int *a; bool t() { return *a==*a; } we get $ more t.C.*original ;; Function bool t() (null) ;; enabled by -tree-original return <retval> = 1; even at -O0 while I think very stupid compiler is allowed to keep the memory access. In fact clang does precisely that: _Z1tv: # @_Z1tv .cfi_startproc # BB#0: pushq %rbp .Ltmp0: .cfi_def_cfa_offset 16 .Ltmp1: .cfi_offset %rbp, -16 movq %rsp, %rbp .Ltmp2: .cfi_def_cfa_register %rbp movq a, %rax movl (%rax), %ecx movq a, %rax cmpl (%rax), %ecx sete %dl andb $1, %dl movzbl %dl, %eax popq %rbp retq .Ltmp3: I am trying to make conservatively correct fix for this. I suppose we can still discover functions seen as const/pure as pure and incrementally teach optimizer that given function does possibly use global memory state but it doesn't depend on it. It should be still correct to CSE those functions. For that we finally need to cleanup pure/const/looping flags into sane form (i.e. clobber memory/has side effects/is CSEable and uses no memory/is CSEable and uses memory)