llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[DAG] foldLogicOfSetCCs - failure to merge bittest ops

Open RKSimon opened this issue 3 months ago • 1 comments

DAG is failing to merge bittest comparisons

define zeroext i1 @src(i8 %x) {
  %a2 = and i8 %x, 4
  %a3 = and i8 %x, 8
  %c2 = icmp ne i8 %a2, 0
  %c3 = icmp ne i8 %a3, 0
  %r = and i1 %c2, %c3
  ret i1 %r
}
define zeroext i1 @tgt(i8 %x) {
  %a23 = and i8 %x, 12
  %r23 = icmp eq i8 %a23, 12
  ret i1 %r23
}
Transformation seems to be correct!

InstCombine handles this with foldLogOpOfMaskedICmps: https://github.com/llvm/llvm-project/blob/0a18f5a00ce532146888e586fba44e586083659e/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L703-L718

There's probably a lot more as well, but let's start with this

RKSimon avatar Aug 07 '26 15:08 RKSimon

Hi @RKSimon, I’d like to work on this issue

Xylecrack avatar Aug 08 '26 14:08 Xylecrack