[llvm-dev] How to eliminate a redundant alloca, load and store?

Riyaz Puthiyapurayil via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 22 17:51:13 PST 2021


In the following code, I know that the alloca, load and store are actually unnecessary (it is safe to pass @foo directly to the function boo). Are there any attributes one can set on function `boo` AND/OR its argument pointer AND/OR on the call so that the three instructions can be eliminated and the argument of call @boo be replaced with @foo (is there a transform that can actually do this today?)

; ModuleID = '<stdin>'
source_filename = "test.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@foo = common dso_local local_unnamed_addr global i32 0, align 4

; Function Attrs: noinline nounwind uwtable
define dso_local void @f() local_unnamed_addr #0 {
  %A = alloca i32, align 4
  %L = load i32, i32* @foo, align 4
  store i32 %L, i32* %A, align 4
 call void @boo(i32* nonnull %A) #2
  ret void
}

declare dso_local void @boo(i32* readonly noalias nocapture) local_unnamed_addr argmemonly #1

attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #2 = { nounwind }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210223/efce4710/attachment.html>


More information about the llvm-dev mailing list