C++ difference in generated x86-64 asm for simple string comparison

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

Could someone explain the difference in generated asm code (x86-64) between

    std::string a{"a"};
    std::string b{"s"};
    std::string c{"d"};
    return s == a || s == b || s == c;

and

    return s == std::string{"a"} ||
        s == std::string{"s"} ||
        s == std::string{"d"};

The former generates less code and I'm not sure why. It looks like the latter
case forbids some kind of optimisations that are possible it the former case.

Please CC me, as I'm not subscribed to this list.

https://godbolt.org/z/K755aEP6n

-- 
/*
 * Serpent7776
 */



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux