Matthias Braun e6382f2111
SelectionDAG: neg (and x, 1) --> SIGN_EXTEND_INREG x, i1 (#131239)
The pattern
```LLVM
%shl = shl i32 %x, 31
%ashr = ashr i32 %shl, 31
```
would be combined to `SIGN_EXTEND_INREG %x, ValueType:ch:i1` by
SelectionDAG.
However InstCombine normalizes this pattern to:
```LLVM
%and = and i32 %x, 1
%neg = sub i32 0, %and
```
This adds matching code to DAGCombiner to catch this variant as well.
2025-03-14 10:47:56 -07:00

26 lines
810 B
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=aarch64-linux-gnu | FileCheck %s
define i62 @f(i1 %0) {
; CHECK-LABEL: f:
; CHECK: // %bb.0:
; CHECK-NEXT: // kill: def $w0 killed $w0 def $x0
; CHECK-NEXT: sbfx x8, x0, #0, #1
; CHECK-NEXT: mov x9, #4611686018427387903 // =0x3fffffffffffffff
; CHECK-NEXT: bics xzr, x9, x8
; CHECK-NEXT: cset w0, ne
; CHECK-NEXT: ret
%2 = zext i1 %0 to i59
%3 = call { i59, i1 } @llvm.umul.with.overflow.i59(i59 %2, i59 -1)
%4 = extractvalue { i59, i1 } %3, 0
%5 = trunc i59 %4 to i21
%6 = trunc i59 %4 to i21
%7 = ashr i21 %5, %6
%8 = sext i21 %7 to i62
%9 = icmp ugt i62 -1, %8
%10 = zext i1 %9 to i62
ret i62 %10
}
declare { i59, i1 } @llvm.umul.with.overflow.i59(i59, i59)