[PATCH] D135738: [InstCombine] Bail out of casting calls when a conversion to byval is involved.

Mike Hommey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 11 20:22:43 PDT 2022


glandium updated this revision to Diff 467004.
glandium added a comment.

Added missing datalayout and target.

(Sorry for the update noise)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135738/new/

https://reviews.llvm.org/D135738

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/test/Transforms/InstCombine/cast-to-byval.ll


Index: llvm/test/Transforms/InstCombine/cast-to-byval.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/cast-to-byval.ll
@@ -0,0 +1,17 @@
+; Check that function calls involving conversion to byval aren't transformed.
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
+target triple = "i686-unknown-linux-gnu"
+
+define i32 @bar(i32 %0) {
+  %2 = tail call i32 @foo(i32 %0)
+; CHECK: %2 = tail call i32 @foo(i32 %0)
+  ret i32 %2
+}
+
+%Foo = type { i32 }
+define i32 @foo (ptr byval(%Foo) %foo) {
+  %1 = load i32, ptr %foo, align 4
+  ret i32 %1
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3395,6 +3395,10 @@
     if (CallerPAL.hasParamAttr(i, Attribute::SwiftError))
       return false;
 
+    if (!CallerPAL.hasParamAttr(i, Attribute::ByVal) &&
+        Callee->getAttributes().hasParamAttr(i, Attribute::ByVal))
+      return false; // Cannot transform to byval.
+
     // If the parameter is passed as a byval argument, then we have to have a
     // sized type and the sized type has to have the same size as the old type.
     if (ParamTy != ActTy && CallerPAL.hasParamAttr(i, Attribute::ByVal)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135738.467004.patch
Type: text/x-patch
Size: 1491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221012/4e4bc049/attachment.bin>


More information about the llvm-commits mailing list