Skip to content

[LLVM][ConstantFolding] missed fold for libcalls with long double constants #19916

@llvmbot

Description

@llvmbot
Bugzilla Link 19542
Version 3.4
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@irishrover

Extended Description

When using mt19937 or mt19937_64 in combination with a uniform_real_distribution, the performance is about an order of magnitude worse than gcc's. But it only happens with that particular combination. Those generators are fine with uniform_int_distribution, and another generator like default_random_engine works fine with uniform_real_distribution. A program to reproduce this and my results:

#include <iostream>
#include <vector>
#include <chrono>
#include <random>

template< typename T_rng, typename T_dist>
double timer(T_rng& rng, T_dist& dist, int n){
    std::vector< typename T_dist::result_type > vec(n, 0);
    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < n; ++i)
        vec[i] = dist(rng);
    auto t2 = std::chrono::high_resolution_clock::now();
    auto runtime = std::chrono::duration_cast<std::chrono::microseconds>(t2-t1).count()/1000.0;
    return runtime;
}

int main(){
    const int n = 10000000;
    std::default_random_engine rng_default(1);
    std::mt19937 rng_mt (1);
    std::mt19937_64 rng_mt_64 (1);
    std::uniform_int_distribution<int> dist_int(0,1000);
    std::uniform_real_distribution<float> dist_float(0.0, 1.0);

    std::cout << "int_default: " << timer(rng_default, dist_int, n) << std::endl;
    std::cout << "int_mt: " << timer(rng_mt_64, dist_int, n) << std::endl;
    std::cout << "int_mt_64: " << timer(rng_mt_64, dist_int, n) << std::endl;
    std::cout << "float_default: " << timer(rng_default, dist_float, n) << std::endl;
    std::cout << "float_mt: " << timer(rng_mt, dist_float, n) << std::endl;
    std::cout << "float_mt_64: " << timer(rng_mt_64, dist_float, n) << std::endl;
}
result for my linux 64bit:
// g++ 4.8.1
int_default: 184.687
int_mt: 176.092
int_mt_64: 176.076
float_default: 45.478
float_mt: 58.018
float_mt_64: 90.073

// clang 3.4
int_default: 207.594
int_mt: 195.68
int_mt_64: 195.702
float_default: 54.535
float_mt: 747.402 <----- slow
float_mt_64: 781.237 <-- slow

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions