Issue 113862
Summary Wrong folding `and` of `icmp`s on undefined values
Labels new issue
Assignees
Reporter bongjunj
    https://github.com/llvm/llvm-project/blob/d3f70db51cbc0876937d404e96fbda04df793bd4/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L2747-L2754


Alive2 report: https://alive2.llvm.org/ce/z/MYjDiS


```llvm
----------------------------------------
define i1 @bitwise_and_bitwise_and_icmps_comm1.2(i8 %x, i8 %y, i8 %z, ptr %#0) {
#1:
  %c1 = icmp eq i8 %y, 42
  %x.m1 = and i8 %x, 1
  %#2 = zext i1 %c1 to i8
  %z.shift = shl i8 1, %#2
  %x.m2 = and i8 %x, %z.shift
  %c2 = icmp ne i8 %x.m1, 0
  %c3 = icmp ne i8 %x.m2, 0
 %#3 = and i1 1, 1
  %and1 = and i1 %#3, %c2
  %and2 = and i1 %c3, %and1
  ret i1 %and2
}
=>
define i1 @bitwise_and_bitwise_and_icmps_comm1.2(i8 %x, i8 %y, i8 %z, ptr %#0) {
#1:
  %c1 = icmp eq i8 %y, 42
  %#2 = zext i1 %c1 to i8
 %z.shift = shl nsw nuw i8 1, %#2
  %#3 = or i8 %z.shift, 1
  %#4 = and i8 %x, %#3
  %and2 = icmp eq i8 %#4, %#3
  ret i1 %and2
}
Transformation doesn't verify!

ERROR: Target's return value is more undefined

Example:
i8 %x = #x03 (3)
i8 %y = undef
i8 %z = #x00 (0)	[based on undef value]
ptr %#0 = null	[based on undef value]

Source:
i1 %c1 = #x0 (0)	[based on undef value]
i8 %x.m1 = #x01 (1)
i8 %#2 = #x00 (0)
i8 %z.shift = #x01 (1)
i8 %x.m2 = #x01 (1)
i1 %c2 = #x1 (1)
i1 %c3 = #x1 (1)
i1 %#3 = #x1 (1)
i1 %and1 = #x1 (1)
i1 %and2 = #x1 (1)

SOURCE MEMORY STATE
===================
NON-LOCAL BLOCKS:
Block 0 >	size: 0	align: 1	alloc type: 0	alive: false	address: 0
Block 1 >	size: 4	align: 1	alloc type: 0	alive: true	address: 1

Target:
i1 %c1 = #x1 (1)
i8 %#2 = #x01 (1)
i8 %z.shift = #x02 (2)
i8 %#3 = #x03 (3)
i8 %#4 = #x03 (3)
i1 %and2 = #x0 (0)
Source value: #x1 (1)
Target value: #x0 (0)

Summary:
  0 correct transformations
  1 incorrect transformations
  0 failed-to-prove transformations
  0 Alive2 errors
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to