https://bugs.llvm.org/show_bug.cgi?id=52003

            Bug ID: 52003
           Summary: Missed optimization: store is dead after destructor
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: davidfromonl...@gmail.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@metafoo.co.uk

The following translation unit when compiled with -O3

```
using Int = int;

void f(Int * ptr) {
        *ptr *= 5;
        ptr->~Int();
}
```

compiles to the IR

```
define dso_local void @_Z1fPi(i32* nocapture %0) local_unnamed_addr #0 !dbg !7
{
  call void @llvm.dbg.value(metadata i32* %0, metadata !15, metadata
!DIExpression()), !dbg !16
  %2 = load i32, i32* %0, align 4, !dbg !17, !tbaa !18
  %3 = mul nsw i32 %2, 5, !dbg !17
  store i32 %3, i32* %0, align 4, !dbg !17, !tbaa !18
  ret void, !dbg !22
}

declare void @llvm.dbg.value(metadata, metadata, metadata) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind uwtable
willreturn "frame-pointer"="none" "min-legal-vector-width"="0"
"no-trapping-math"="true" "stack-protector-buffer-size"="8"
"target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87"
"tune-cpu"="generic" }
attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
```

or the assembly

```
f(int*): # @f(int*)
  movl (%rdi), %eax
  leal (%rax,%rax,4), %eax
  movl %eax, (%rdi)
  retq
```

This function should instead be a no-op because the memory written to no longer
contains an integer.

https://godbolt.org/z/4dqThehhK

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to