Don't drop attributes when inlining through "deopt" operand bundles
authorSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 9 Dec 2015 01:01:28 +0000 (01:01 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 9 Dec 2015 01:01:28 +0000 (01:01 +0000)
Test case attached (test case also checks that we don't drop the calling
convention, but that functionality was correct before this patch).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255088 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Instructions.cpp
test/Transforms/Inline/deopt-bundles.ll

index bba0ef2d7d348c28abe02d69d7eeaa632ff66430..6ec2e28997009fcc689a2c38d063c352a6739327 100644 (file)
@@ -307,6 +307,7 @@ CallInst *CallInst::Create(CallInst *CI, ArrayRef<OperandBundleDef> OpB,
   NewCI->setTailCallKind(CI->getTailCallKind());
   NewCI->setCallingConv(CI->getCallingConv());
   NewCI->SubclassOptionalData = CI->SubclassOptionalData;
+  NewCI->setAttributes(CI->getAttributes());
   return NewCI;
 }
 
@@ -594,6 +595,7 @@ InvokeInst *InvokeInst::Create(InvokeInst *II, ArrayRef<OperandBundleDef> OpB,
                                    II->getName(), InsertPt);
   NewII->setCallingConv(II->getCallingConv());
   NewII->SubclassOptionalData = II->SubclassOptionalData;
+  NewII->setAttributes(II->getAttributes());
   return NewII;
 }
 
index 91d4690e0e61dc557450cee6b79908a4db57872a..b4176089075e796f237a6852edc17bb2efd36ddd 100644 (file)
@@ -2,6 +2,7 @@
 
 declare void @f()
 declare i32 @g()
+declare fastcc i32 @g.fastcc()
 
 define i32 @callee_0() alwaysinline {
  entry:
@@ -95,3 +96,41 @@ define i32 @caller_4() {
   %x = call i32 @callee_4() [ "deopt"(i32 7) ]
   ret i32 %x
 }
+
+define i32 @callee_5() alwaysinline personality i8 3 {
+ entry:
+  %v = invoke fastcc i32 @g.fastcc() #0 [ "deopt"(i32 0, i32 1), "foo"(double 0.0) ] to label %normal unwind label %unwind
+
+ normal:
+  ret i32 %v
+
+ unwind:
+  %cleanup = landingpad i8 cleanup
+  ret i32 100
+}
+
+define i32 @caller_5() {
+; CHECK-LABEL: @caller_5(
+ entry:
+; CHECK:  invoke fastcc i32 @g.fastcc() #[[FOO_BAR_ATTR_IDX:[0-9]+]] [ "deopt"(i32 7, i32 0, i32 1), "foo"(double 0.000000e+00) ]
+  %x = call i32 @callee_5() [ "deopt"(i32 7) ]
+  ret i32 %x
+}
+
+define i32 @callee_6() alwaysinline personality i8 3 {
+ entry:
+  %v = call fastcc i32 @g.fastcc() #0 [ "deopt"(i32 0, i32 1), "foo"(double 0.0) ]
+  ret i32 %v
+}
+
+define i32 @caller_6() {
+; CHECK-LABEL: @caller_6(
+ entry:
+; CHECK: call fastcc i32 @g.fastcc() #[[FOO_BAR_ATTR_IDX]] [ "deopt"(i32 7, i32 0, i32 1), "foo"(double 0.000000e+00) ]
+  %x = call i32 @callee_6() [ "deopt"(i32 7) ]
+  ret i32 %x
+}
+
+attributes #0 = { "foo"="bar" }
+
+; CHECK: attributes #[[FOO_BAR_ATTR_IDX]] = { "foo"="bar" }