[all-commits] [llvm/llvm-project] 6b9487: [AggressiveInstCombine] Inline strcmp/strncmp (#89...

Franklin Zhang via All-commits all-commits at lists.llvm.org
Thu May 2 21:25:00 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6b948705a05261a2ff31cd7e6ea8319d1852ddfc
      https://github.com/llvm/llvm-project/commit/6b948705a05261a2ff31cd7e6ea8319d1852ddfc
  Author: Franklin Zhang <zhangfenglei at huawei.com>
  Date:   2024-05-03 (Fri, 03 May 2024)

  Changed paths:
    M llvm/include/llvm/Analysis/ValueTracking.h
    M llvm/include/llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h
    M llvm/lib/Analysis/ValueTracking.cpp
    M llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
    R llvm/test/Transforms/AggressiveInstCombine/strcmp.ll
    A llvm/test/Transforms/AggressiveInstCombine/strncmp-1.ll
    A llvm/test/Transforms/AggressiveInstCombine/strncmp-2.ll

  Log Message:
  -----------
  [AggressiveInstCombine] Inline strcmp/strncmp (#89371)

Inline calls to strcmp(s1, s2) and strncmp(s1, s2, N), where N and
exactly one of s1 and s2 are constant.

For example:

```c
int res = strcmp(s, "ab");
```

is converted to

```c
int res = (int)s[0] - (int)'a';
if (res != 0)
  goto END;
res = (int)s[1] - (int)'b';
if (res != 0)
  goto END;
res = (int)s[2] - (int)'\0';
END:
```

Ported from a similar gcc feature [Inline strcmp with small constant
strings](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list