[llvm-bugs] [Bug 46965] New: Miss optimization for consecutive character equality testing

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 3 05:41:00 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46965

            Bug ID: 46965
           Summary: Miss optimization for consecutive character equality
                    testing
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zufuliu at 163.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

For following code (online at https://godbolt.org/z/3oxx69)
```
template <typename T, typename... Args>
constexpr bool AnyOf(T t, Args... args) noexcept {
    return ((t == args) || ...);
}

bool Escape1(int ch) noexcept {
    return AnyOf(ch, '\\', '\'', '\"', 'a', 'b', 'e',
                'f', 'n', 'r', 't', 'x', 'u', 'U');
}

bool Escape2(int ch) noexcept {
    return ch == '\\' || ch == '\'' || ch == '\"'
        || ch == 'a' || ch == 'b' || ch == 'e' 
        || ch == 'f' || ch == 'n' || ch == 'r' || ch == 't'
        || ch == 'x' || ch == 'u' || ch == 'U';
}

```

Clang (and GCC, ICC) generates different code for Escape1 and Escape2, while
MSVC generates identical code. Clang also generates different code when
parameter `int ch` is changed to `char ch`.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200803/3fed18a6/attachment.html>


More information about the llvm-bugs mailing list