Issue 164436
Summary [InstCombine] Failure to recognise CTTZ pattern using CTLZ
Labels good first issue, llvm:instcombine, missed-optimization
Assignees
Reporter RKSimon
    While we correctly fold this hackers delight ctpop pattern into ctz:
```ll
define i4 @src_ctpop(i4 %a0) {
  %dec = add i4 %a0, -1
  %not = xor i4 %a0, -1
 %and = and i4 %dec, %not
  %clz = tail call i4 @llvm.ctpop.i4(i4 %and)
 ret i4 %clz
}
define i4 @tgt_ctpop(i4 %a0) {
  %ctz = tail call i4 @llvm.cttz.i4(i4 %a0, i1 false)
  ret i4 %ctz
}
```
we fail to recognise the related clz pattern:
```ll
define i4 @src_lz(i4 %a0) {
  %dec = add i4 %a0, -1
  %not = xor i4 %a0, -1
  %and = and i4 %dec, %not
  %clz = tail call i4 @llvm.ctlz.i4(i4 %and, i1 false) ; undef = true is ok as well
  %ctz = sub i4 4, %clz
  ret i4 %ctz
}
define i4 @tgt_lz(i4 %a0) {
  %ctz = tail call i4 @llvm.cttz.i4(i4 %a0, i1 false)
  ret i4 %ctz
}
```

Alive2: https://alive2.llvm.org/ce/z/AdPVa5
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to