[llvm] [ValueTracking] Let ComputeKnownSignBits handle (shl (zext X), C) (PR #97693)
Björn Pettersson via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 4 04:33:48 PDT 2024
bjope wrote:
> This looks reasonable to me. Can you replace the unit tests with lit tests please?
I don't really know how to make good lit tests for ComputeNumSignBits.
All I've got is something like this
```
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
define i16 @numsignbits_shl_zext(i8 %a) {
%nsb6 = ashr i8 %a, 6
%zext = zext i8 %nsb6 to i16
%nsb4 = shl i16 %zext, 10
%or = or i16 %nsb4, 1
; With four sign bits this should be nsw.
%shl = add i16 %nsb4, 4096
ret i16 %shl
}
```
to show that the `add` will get a `nsw`. But it far from verifies that ComputeNumSignBits actually is returning the correct value. Isn't it much easier to verify the correct behavior via the unit test?
Maybe I should add a lit test like the one above as a complement, to show that it is possible to trigger this via a lit test as well (even though it doesn't validate that the calculation in ComputeNumSignBits is correct).
https://github.com/llvm/llvm-project/pull/97693
More information about the llvm-commits
mailing list