Fix a pretty scary bug I introduced into the always inliner with
authorChandler Carruth <chandlerc@gmail.com>
Sun, 1 Apr 2012 10:21:05 +0000 (10:21 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 1 Apr 2012 10:21:05 +0000 (10:21 +0000)
a single missing character. Somehow, this had gone untested. I've added
tests for returns-twice logic specifically with the always-inliner that
would have caught this, and fixed the bug.

Thanks to Matt for the careful review and spotting this!!! =D

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

lib/Transforms/IPO/InlineAlways.cpp
test/Transforms/Inline/always-inline.ll

index a977027eed1eaf78637c1ff69300e5dc6d4d3f26..664ddf6f7a2b500a04cc6faf95ded9d7386ec56a 100644 (file)
@@ -83,7 +83,7 @@ static bool isInlineViable(Function &F) {
 
       // Disallow calls which expose returns-twice to a function not previously
       // attributed as such.
-      if (ReturnsTwice && CS.isCall() &&
+      if (!ReturnsTwice && CS.isCall() &&
           cast<CallInst>(CS.getInstruction())->canReturnTwice())
         return false;
     }
index 40091d7518a4f1271fcd83a4489f6bc01f3a6ea5..bfd8762713dbfe6e1625002a0a3f9fbf8b8836a3 100644 (file)
@@ -40,3 +40,41 @@ define void @outer2(i32 %N) {
   call void @inner2( i32 %N )
   ret void
 }
+
+declare i32 @a() returns_twice
+declare i32 @b() returns_twice
+
+define i32 @inner3() alwaysinline {
+entry:
+  %call = call i32 @a() returns_twice
+  %add = add nsw i32 1, %call
+  ret i32 %add
+}
+define i32 @outer3() {
+entry:
+; CHECK: @outer3
+; CHECK-NOT: call i32 @a
+; CHECK: ret
+
+  %call = call i32 @inner3()
+  %add = add nsw i32 1, %call
+  ret i32 %add
+}
+
+define i32 @inner4() alwaysinline returns_twice {
+entry:
+  %call = call i32 @b() returns_twice
+  %add = add nsw i32 1, %call
+  ret i32 %add
+}
+
+define i32 @outer4() {
+entry:
+; CHECK: @outer4
+; CHECK: call i32 @b()
+; CHECK: ret
+
+  %call = call i32 @inner4() returns_twice
+  %add = add nsw i32 1, %call
+  ret i32 %add
+}