Open
Description
$ clang-trunk --version
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 1964118ace4926f4d103aa0538db1f1f5baa343a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
$ clang-17 --version
clang version 17.0.3
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
$ cat abc.c
int a, b, c;
int d(int e) { return e; }
void main() {
int l_4516;
c = d(1);
l_4516 = 1 && c;
b = l_4516 & a
;
}
$ clang-17 abc.c -g -O3
$ lldb ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '<datapath>/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '<datapath>/cmds'.
(lldb) b 7
Breakpoint 1: where = a.out`main + 10 at abc.c:7:16, address = 0x000000000000114a
(lldb) r
Process 2161844 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x000055555555514a a.out`main at abc.c:7:16
4 int l_4516;
5 c = d(1);
6 l_4516 = 1 && c;
-> 7 b = l_4516 & a
8 ;
9 }
Process 2161844 launched: '<datapath>/a.out' (x86_64)
(lldb) p l_4516
(int) $0 = 1
(lldb) kill
Process 2161844 exited with status = 9 (0x00000009)
(lldb) q
$ clang-trunk abc.c -g -O3
$ lldb ./a.out -s cmds
(lldb) target create "./a.out"
Current executable set to '<datapath>/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '<datapath>/cmds'.
(lldb) b 7
Breakpoint 1: where = a.out`main + 10 at abc.c:7:16, address = 0x000000000000114a
(lldb) r
Process 2162193 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
frame #0: 0x000055555555514a a.out`main at abc.c:7:16
4 int l_4516;
5 c = d(1);
6 l_4516 = 1 && c;
-> 7 b = l_4516 & a
8 ;
9 }
Process 2162193 launched: '<datapath>/a.out' (x86_64)
(lldb) p l_4516
(int) $0 = 0
(lldb) kill
Process 2162193 exited with status = 9 (0x00000009)
(lldb) q
$ cat cmds
b 7
r
p l_4516
kill
q
The value printed using lldb in clang-16 -O3 ('\x01') and clang-17 -O3 ('\xff') are different.
By using git bisection, we find that this issue was introduced in the following commit:
commit a7f962c
Author: Yingwei Zheng dtcxzyw2333@gmail.com @dtcxzyw
Date: Fri Sep 29 02:51:58 2023 +0800
[InstCombine] Canonicalize `and(zext(A), B)` into `select A, B & 1, 0` (#66740)
This patch canonicalizes the pattern `and(zext(A), B)` into `select A, B
& 1, 0`. Thus, we can reuse transforms `select B == even, B & 1, 0 -> 0`
and `select B == odd, B & 1, 0 -> zext(B == odd)` in `InstCombine`.
It is an alternative to #66676.
Alive2: https://alive2.llvm.org/ce/z/598phE
Fixes #66733.
Fixes #66606.
Fixes #28612.