[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
Thu Oct 20 14:50:58 PDT 2022


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

Removed datalayout/Ran update_test_checks


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,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; Check that function calls involving conversion to byval aren't transformed.
+; RUN: opt < %s -passes=instcombine -mtriple=x86_64-unknown-unknown -S | FileCheck %s
+
+%Foo = type { i64 }
+define i64 @foo (ptr byval(%Foo) %foo) {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:    [[TMP1:%.*]] = load i64, ptr [[FOO:%.*]], align 4
+; CHECK-NEXT:    ret i64 [[TMP1]]
+;
+  %1 = load i64, ptr %foo, align 4
+  ret i64 %1
+}
+
+define i64 @bar(i64 %0) {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:    [[TMP2:%.*]] = tail call i64 @foo(i64 [[TMP0:%.*]])
+; CHECK-NEXT:    ret i64 [[TMP2]]
+;
+  %2 = tail call i64 @foo(i64 %0)
+  ret i64 %2
+}
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.469365.patch
Type: text/x-patch
Size: 1669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221020/1bd71b7c/attachment.bin>


More information about the llvm-commits mailing list