Skip to content

[InstCombine] range attribute should be dropped in foldIsPowerOf2OrZero #112078

Closed
@dtcxzyw

Description

@dtcxzyw

Reproducer: https://alive2.llvm.org/ce/z/u62KKP (Please use latest alive2 with AliveToolkit/alive2#1097)

define i1 @src(i32 %x) {
  %t0 = tail call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)
  %cmp = icmp ne i32 %t0, 1
  %notzero = icmp ne i32 %x, 0
  %r = select i1 %notzero, i1 %cmp, i1 false
  ret i1 %r
}

define i1 @tgt(i32 %x) {
  %t0 = tail call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)
  %r = icmp ugt i32 %t0, 1
  ret i1 %r
}
----------------------------------------
define i1 @src(i32 %x) {
#0:
  %t0 = ctpop i32 %x
  %#range_0_%t0 = !range i32 %t0, i32 1, i32 33
  %cmp = icmp ne i32 %#range_0_%t0, 1
  %notzero = icmp ne i32 %x, 0
  %r = select i1 %notzero, i1 %cmp, i1 0
  ret i1 %r
}
=>
define i1 @tgt(i32 %x) {
#0:
  %t0 = ctpop i32 %x
  %#range_0_%t0 = !range i32 %t0, i32 1, i32 33
  %r = icmp ugt i32 %#range_0_%t0, 1
  ret i1 %r
}
Transformation doesn't verify!

ERROR: Target is more poisonous than source

Example:
i32 %x = #x00000000 (0)

Source:
i32 %t0 = #x00000000 (0)
i32 %#range_0_%t0 = poison
i1 %cmp = poison
i1 %notzero = #x0 (0)
i1 %r = #x0 (0)

Target:
i32 %t0 = #x00000000 (0)
i32 %#range_0_%t0 = poison
i1 %r = poison
Source value: #x0 (0)
Target value: poison

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions