Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[memcpyopt] fails to eliminate memcpy fed by sret #2590

Closed
llvmbot opened this issue Apr 11, 2008 · 3 comments
Closed

[memcpyopt] fails to eliminate memcpy fed by sret #2590

llvmbot opened this issue Apr 11, 2008 · 3 comments
Labels
bugzilla Issues migrated from bugzilla llvm:optimizations

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 11, 2008

Bugzilla Link 2218
Version unspecified
OS Linux
Attachments testcase .ll
Reporter LLVM Bugzilla Contributor
CC @efriedma-quic

Extended Description

Here's the testcase (also attached). %pointless could be
eliminated since no use is ever made of it except as a
memcpy target. %temporary could also be eliminated in
favour of passing %result directly to the @​initialize call.

define void @​f(i8* noalias sret %result) {
entry:
%temporary = alloca i8 ; <i8*> [#uses=3]
%pointless = alloca i8 ; <i8*> [#uses=1]
call void @​initialize( i8* noalias sret %temporary )
call void @​llvm.memcpy.i32( i8* %pointless, i8* %temporary, i32 1, i32 4 )
call void @​llvm.memcpy.i32( i8* %result, i8* %temporary, i32 1, i32 4 )
ret void
}

declare void @​initialize(i8* noalias sret )
declare void @​llvm.memcpy.i32(i8*, i8*, i32, i32) nounwind

@efriedma-quic
Copy link
Collaborator

Running the given testcase through opt -dse -memcpyopt -dce does the desired reductions, but opt -std-compile-opts doesn't.

@lattner
Copy link
Collaborator

lattner commented Nov 18, 2010

This is two issues:

  1. memcpyopt should delete memcpy's that store to otherwise dead allocas as general cleanup like DSE does.
  2. we don't optimize a memcpy fed by a sret aggressively, like:

define void @​f(i8* noalias sret %result) {
entry:
%temporary = alloca i8
call void @​initialize(i8* noalias sret %temporary)
call void @​llvm.memcpy.p0i8.p0i8.i32(i8* %result, i8* %temporary, i32 1, i32 4, i1 false)
ret void
}

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
cyndyishida pushed a commit to cyndyishida/llvm-project that referenced this issue Jun 17, 2022
Tweak async calling convention patches to reflect upstream changes
@arsenm
Copy link
Contributor

arsenm commented Aug 4, 2023

opt -O2 through modernized testcase removes all the memcpies:

define void @f(ptr noalias sret(i8) %result) {
entry:
  %temporary = alloca i8, align 1
  %pointless = alloca i8, align 1
  call void @initialize(ptr noalias sret(i8) %temporary)
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %pointless, ptr align 4 %temporary, i32 1, i1 false)
  call void @llvm.memcpy.p0.p0.i32(ptr align 4 %result, ptr align 4 %temporary, i32 1, i1 false)
  ret void
}

declare void @initialize(ptr noalias sret(i8))

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg) #0

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:optimizations
Projects
None yet
Development

No branches or pull requests

6 participants