Issue 184131
Summary Select of lshr not converted to lshr of select with one multi-use operand
Labels llvm:instcombine, missed-optimization
Assignees
Reporter nikic
    From https://github.com/rust-lang/rust/pull/151780.

https://alive2.llvm.org/ce/z/AHRhE2
```llvm
define i16 @or(i16 %0, i16 %1) {
start:
  %.sroa.0.0.extract.shift = lshr i16 %0, 8
  %2 = trunc i16 %.sroa.0.0.extract.shift to i1
 %_0.sroa.0.0.extract.shift = lshr i16 %1, 8
  %_0.sroa.0.0.v = select i1 %2, i16 %.sroa.0.0.extract.shift, i16 %_0.sroa.0.0.extract.shift
 %_0.sroa.3.0.v = select i1 %2, i16 %0, i16 %1
  %_0.sroa.3.0.insert.ext = and i16 %_0.sroa.3.0.v, 255
  %_0.sroa.0.0.insert.shift = shl nuw i16 %_0.sroa.0.0.v, 8
  %_0.sroa.0.0.insert.insert = or disjoint i16 %_0.sroa.0.0.insert.shift, %_0.sroa.3.0.insert.ext
  ret i16 %_0.sroa.0.0.insert.insert
}

define i16 @tgt(i16 %0, i16 %1) {
start:
 %2 = and i16 %0, 256
  %.not = icmp eq i16 %2, 0
  %_0.sroa.3.0.v = select i1 %.not, i16 %1, i16 %0
  ret i16 %_0.sroa.3.0.v
}
```

This would simplify if the select of lshr would be converted into lshr of select, but this doesn't happen because one of the operands is multi-use.

Possibly we can relax this fold to allow one multi-use operand, not sure if that will cause other issues.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to