PartiallyInlineLibCalls: Check sqrt result type before transforming it.
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 1 Aug 2014 23:21:21 +0000 (23:21 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 1 Aug 2014 23:21:21 +0000 (23:21 +0000)
Some configure scripts declare this with the wrong prototype, which can lead
to an assertion failure.

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

lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp
test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll [new file with mode: 0644]

index 7cce89e0627e6301ded31fef9da3bf146f546ee9..5c8bed585b640c54904850d8e13f7f026daa0722 100644 (file)
@@ -108,6 +108,10 @@ bool PartiallyInlineLibCalls::optimizeSQRT(CallInst *Call,
   if (Call->onlyReadsMemory())
     return false;
 
   if (Call->onlyReadsMemory())
     return false;
 
+  // The call must have the expected result type.
+  if (!Call->getType()->isFloatingPointTy())
+    return false;
+
   // Do the following transformation:
   //
   // (before)
   // Do the following transformation:
   //
   // (before)
diff --git a/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll b/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll
new file mode 100644 (file)
index 0000000..34cd672
--- /dev/null
@@ -0,0 +1,13 @@
+; RUN: opt -S -partially-inline-libcalls < %s | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+declare i32 @sqrt()
+
+; CHECK-LABEL: @foo
+define i32 @foo() {
+  ; CHECK: call{{.*}}@sqrt
+  ; CHECK-NOT: call{{.*}}@sqrt
+  %r = call i32 @sqrt()
+  ret i32 %r
+}