[llvm] r281144 - InstCombine: Don't combine loads/stores from swifterror to a new type

Arnold Schwaighofer via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 10 11:14:57 PDT 2016


Author: arnolds
Date: Sat Sep 10 13:14:57 2016
New Revision: 281144

URL: http://llvm.org/viewvc/llvm-project?rev=281144&view=rev
Log:
InstCombine: Don't combine loads/stores from swifterror to a new type

This generates invalid IR: the only users of swifterror can be call
arguments, loads, and stores.

rdar://28242257

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
    llvm/trunk/test/Transforms/InstCombine/bitcast-store.ll
    llvm/trunk/test/Transforms/InstCombine/load.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=281144&r1=281143&r2=281144&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Sat Sep 10 13:14:57 2016
@@ -465,6 +465,10 @@ static Instruction *combineLoadToOperati
   if (LI.use_empty())
     return nullptr;
 
+  // swifterror values can't be bitcasted.
+  if (LI.getPointerOperand()->isSwiftError())
+    return nullptr;
+
   Type *Ty = LI.getType();
   const DataLayout &DL = IC.getDataLayout();
 
@@ -997,6 +1001,10 @@ static bool combineStoreToValueType(Inst
   if (!SI.isUnordered())
     return false;
 
+  // swifterror values can't be bitcasted.
+  if (SI.getPointerOperand()->isSwiftError())
+    return false;
+
   Value *V = SI.getValueOperand();
 
   // Fold away bit casts of the stored value by storing the original type.

Modified: llvm/trunk/test/Transforms/InstCombine/bitcast-store.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bitcast-store.ll?rev=281144&r1=281143&r2=281144&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/bitcast-store.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/bitcast-store.ll Sat Sep 10 13:14:57 2016
@@ -32,4 +32,19 @@ entry:
   ret void
 }
 
+; Check that we don't combine the bitcast into the store. This would create a
+; bitcast of the swifterror which is invalid.
+
+; CHECK-LABEL; @swifterror_store
+; CHECK: bitcast i64
+; CHECK: store %swift.error
+
+%swift.error = type opaque
+define void @swifterror_store(i64* %x, %swift.error** swifterror %err) {
+entry:
+  %casted = bitcast i64* %x to %swift.error*
+  store %swift.error* %casted, %swift.error** %err
+  ret void
+}
+
 !0 = !{!0}

Modified: llvm/trunk/test/Transforms/InstCombine/load.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/load.ll?rev=281144&r1=281143&r2=281144&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/load.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/load.ll Sat Sep 10 13:14:57 2016
@@ -201,3 +201,21 @@ entry:
 
   ret void
 }
+
+; Check that we don't try change the type of the load by inserting a bitcast
+; generating invalid IR.
+; CHECK-LABEL: @test18(
+; CHECK-NOT: bitcast
+; CHECK: ret
+%swift.error = type opaque
+declare void @useSwiftError(%swift.error** swifterror)
+
+define void @test18(%swift.error** swifterror %err) {
+entry:
+  %swifterror = alloca swifterror %swift.error*, align 8
+  store %swift.error* null, %swift.error** %swifterror, align 8
+  call void @useSwiftError(%swift.error** nonnull swifterror %swifterror)
+  %err.res = load %swift.error*, %swift.error** %swifterror, align 8
+  store %swift.error* %err.res, %swift.error** %err, align 8
+  ret void
+}




More information about the llvm-commits mailing list