Issue 113863
Summary Wrong folding a binary operator into PHI
Labels new issue
Assignees
Reporter bongjunj
    https://github.com/llvm/llvm-project/blob/d3f70db51cbc0876937d404e96fbda04df793bd4/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L2023-L2035

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

```llvm
----------------------------------------
define i64 @constant_range_and_undef2.2(i1 %c1, i1 %c2, i64 %a) {
entry:
  br i1 %c1, label %bb1, label %bb2

bb2:
  %v2 = and i64 %a, 4294967295
  br label %bb3

bb1:
  br label %bb3

bb3:
 %p = phi i64 [ poison, %bb1 ], [ %v2, %bb2 ]
  br i1 %c2, label %bb4, label %bb5

bb4:
  br label %bb6

bb5:
  br label %bb6

bb6:
  %p2 = phi i64 [ %p, %bb4 ], [ undef, %bb5 ]
  %res = and i64 %p2, 255
  ret i64 %res
}
=>
define i64 @constant_range_and_undef2.2(i1 %c1, i1 %c2, i64 %a) {
entry:
  br i1 %c1, label %bb1, label %bb2

bb2:
  %#0 = and i64 %a, 255
  br label %bb3

bb1:
  br label %bb3

bb3:
  %p = phi i64 [ poison, %bb1 ], [ %#0, %bb2 ]
  br i1 %c2, label %bb4, label %bb5

bb4:
  br label %bb6

bb5:
  br label %bb6

bb6:
  ret i64 %p
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i1 %c1 = #x1 (1)
i1 %c2 = #x0 (0)
i64 %a = #x0000000000000000 (0)

Source:
  >> Jump to %bb1
  >> Jump to %bb3
i64 %p = poison
  >> Jump to %bb5
  >> Jump to %bb6
i64 %p2 = #x0000000000000000 (0)	[based on undef value]
i64 %res = #x0000000000000000 (0)

Target:
  >> Jump to %bb1
  >> Jump to %bb3
i64 %p = poison
  >> Jump to %bb5
  >> Jump to %bb6
Source value: #x0000000000000000 (0)
Target value: poison

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