LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 24952 - miscompile from r248638
Summary: miscompile from r248638
Status: RESOLVED FIXED
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P normal
Assignee: Sanjoy Das
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-27 04:53 PDT by Yaron Keren
Modified: 2015-09-27 16:21 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yaron Keren 2015-09-27 04:53:37 PDT
The boost example,

#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <iostream>
int main() {
   using namespace boost::multiprecision;
   std::cout << boost::math::tgamma(cpp_bin_float_100(1000)) << std::endl;
}

produce correct output

bin/clang++ -O2 -std=c++11 -isystem include cpp_bin_float_snips.cpp
./a.out
4.02387e+2564

with pre-r248638 clang and gcc 5.1.0.

From r248638,

./a.out
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::range_error> >'
  what():  No bits were set in the operand.

this is on Ubunto 14.04 64 bit, boost 1.57.
Comment 1 Sanjoy Das 2015-09-27 13:47:21 PDT
I think this is a glitch with how isIdenticalTo is used in
ScalarEvolution.

Can you check if clang built with this patch below fixes the issue?

diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 32d3d36..bfd6c45 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -6418,7 +6418,8 @@ static bool HasSameValue(const SCEV *A, const SCEV *B) {
     if (const SCEVUnknown *BU = dyn_cast<SCEVUnknown>(B))
       if (const Instruction *AI = dyn_cast<Instruction>(AU->getValue()))
         if (const Instruction *BI = dyn_cast<Instruction>(BU->getValue()))
-          if (AI->isIdenticalTo(BI) && !AI->mayReadFromMemory())
+          if (AI->isIdenticalTo(BI) && !AI->mayReadFromMemory() &&
+              !isa<AllocaInst>(AI))
             return true;
 
   // Otherwise assume they may have a different value.
Comment 2 Yaron Keren 2015-09-27 13:53:47 PDT
Yes, this patch does solve the problem.
Thanks for looking into this!
Comment 3 Sanjoy Das 2015-09-27 16:14:04 PDT
Should be fixed in r248690
Comment 4 Yaron Keren 2015-09-27 16:21:05 PDT
Confirmed, r248690 fixes the problem.