Noah Goldstein d81db0e5f5 [KnownBits] Implement knownbits lshr/ashr with exact flag
The exact flag basically allows us to set an upper bound on shift
amount when we have a known 1 in `LHS`.

Typically we deduce exact using knownbits (on non-exact incoming
shifts), so this is particularly impactful, but may be useful in some
circumstances.

Closes #84254
2024-03-11 15:51:07 -05:00

21 lines
493 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
define i8 @simplify_lshr_with_exact(i8 %x) {
; CHECK-LABEL: @simplify_lshr_with_exact(
; CHECK-NEXT: ret i8 2
;
%shr = lshr exact i8 6, %x
%r = and i8 %shr, 2
ret i8 %r
}
define i8 @simplify_ashr_with_exact(i8 %x) {
; CHECK-LABEL: @simplify_ashr_with_exact(
; CHECK-NEXT: ret i8 2
;
%shr = ashr exact i8 -122, %x
%r = and i8 %shr, 2
ret i8 %r
}