[llvm] 53f4c4b - [InstCombine] Do not introduce bitcasts for swifterror arguments.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 28 14:52:56 PDT 2020


Author: Florian Hahn
Date: 2020-10-28T21:52:12Z
New Revision: 53f4c4b2cc51f4848dfc610a3a858ef821e39ae5

URL: https://github.com/llvm/llvm-project/commit/53f4c4b2cc51f4848dfc610a3a858ef821e39ae5
DIFF: https://github.com/llvm/llvm-project/commit/53f4c4b2cc51f4848dfc610a3a858ef821e39ae5.diff

LOG: [InstCombine] Do not introduce bitcasts for swifterror arguments.

The following constraints hold for swifterror values:

    A swifterror value (either the parameter or the alloca) can only
    be loaded and stored from, or used as a swifterror argument.

This patch updates instcombine to not try to convert a bitcast of a
function into a bitcast of a swifterror argument.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D90258

Added: 
    llvm/test/Transforms/InstCombine/swifterror-argument-bitcast-fold.ll

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index c06965780929..3b0b12d4d742 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2126,6 +2126,9 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
     if (Call.isInAllocaArgument(i))
       return false;   // Cannot transform to and from inalloca.
 
+    if (CallerPAL.hasParamAttribute(i, Attribute::SwiftError))
+      return false;
+
     // 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.hasParamAttribute(i, Attribute::ByVal)) {

diff  --git a/llvm/test/Transforms/InstCombine/swifterror-argument-bitcast-fold.ll b/llvm/test/Transforms/InstCombine/swifterror-argument-bitcast-fold.ll
new file mode 100644
index 000000000000..22a98f382578
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/swifterror-argument-bitcast-fold.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -instcombine -S %s | FileCheck %s
+
+; The swifterror value can only be loaded, stored or used as swifterror
+; argument. Make sure we do not try to turn the function bitcast into an
+; argument bitcast.
+define swiftcc void @spam(i32** swifterror %arg) {
+; CHECK-LABEL: @spam(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    call swiftcc void bitcast (void (i64**)* @widget to void (i32**)*)(i32** swifterror [[ARG:%.*]])
+; CHECK-NEXT:    ret void
+;
+bb:
+  call swiftcc void bitcast (void (i64**)* @widget to void (i32**)*)(i32** swifterror %arg)
+  ret void
+}
+
+declare swiftcc void @widget(i64**)


        


More information about the llvm-commits mailing list