mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 13:11:39 +01:00
b6a12c439f
This is almost the same as an existing IR canonicalization in instcombine, so I'm assuming this is a good early generic DAG combine too. The motivation comes from reduced bit-hacking for select-of-constants in IR after rL331486. We want to restore that functionality in the DAG as noted in the commit comments for that change and the llvm-dev discussion here: http://lists.llvm.org/pipermail/llvm-dev/2018-July/124433.html The PPC and AArch tests show that those targets are already doing something similar. x86 will be neutral in the minimal case and generally better when this pattern is extended with other ops as shown in the signbit-shift.ll tests. Note the asymmetry: we don't include the (extend (ifneg X)) transform because it already exists in SimplifySelectCC(), and that is verified in the later unchanged tests in the signbit-shift.ll files. Without the 'not' op, the general transform to use a shift is always a win because that's a single instruction. Alive proofs: https://rise4fun.com/Alive/ysli Name: if pos, get -1 %c = icmp sgt i16 %x, -1 %r = sext i1 %c to i16 => %n = xor i16 %x, -1 %r = ashr i16 %n, 15 Name: if pos, get 1 %c = icmp sgt i16 %x, -1 %r = zext i1 %c to i16 => %n = xor i16 %x, -1 %r = lshr i16 %n, 15 Differential Revision: https://reviews.llvm.org/D48970 llvm-svn: 337130
152 lines
3.4 KiB
LLVM
152 lines
3.4 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc < %s -mtriple=powerpc64le-- | FileCheck %s
|
|
|
|
; If positive...
|
|
|
|
define i32 @zext_ifpos(i32 %x) {
|
|
; CHECK-LABEL: zext_ifpos:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: nor 3, 3, 3
|
|
; CHECK-NEXT: srwi 3, 3, 31
|
|
; CHECK-NEXT: blr
|
|
%c = icmp sgt i32 %x, -1
|
|
%e = zext i1 %c to i32
|
|
ret i32 %e
|
|
}
|
|
|
|
define i32 @add_zext_ifpos(i32 %x) {
|
|
; CHECK-LABEL: add_zext_ifpos:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: nor 3, 3, 3
|
|
; CHECK-NEXT: srwi 3, 3, 31
|
|
; CHECK-NEXT: addi 3, 3, 41
|
|
; CHECK-NEXT: blr
|
|
%c = icmp sgt i32 %x, -1
|
|
%e = zext i1 %c to i32
|
|
%r = add i32 %e, 41
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @sel_ifpos_tval_bigger(i32 %x) {
|
|
; CHECK-LABEL: sel_ifpos_tval_bigger:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: li 4, 41
|
|
; CHECK-NEXT: cmpwi 0, 3, -1
|
|
; CHECK-NEXT: li 3, 42
|
|
; CHECK-NEXT: isel 3, 3, 4, 1
|
|
; CHECK-NEXT: blr
|
|
%c = icmp sgt i32 %x, -1
|
|
%r = select i1 %c, i32 42, i32 41
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @sext_ifpos(i32 %x) {
|
|
; CHECK-LABEL: sext_ifpos:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: nor 3, 3, 3
|
|
; CHECK-NEXT: srawi 3, 3, 31
|
|
; CHECK-NEXT: blr
|
|
%c = icmp sgt i32 %x, -1
|
|
%e = sext i1 %c to i32
|
|
ret i32 %e
|
|
}
|
|
|
|
define i32 @add_sext_ifpos(i32 %x) {
|
|
; CHECK-LABEL: add_sext_ifpos:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: nor 3, 3, 3
|
|
; CHECK-NEXT: srawi 3, 3, 31
|
|
; CHECK-NEXT: addi 3, 3, 42
|
|
; CHECK-NEXT: blr
|
|
%c = icmp sgt i32 %x, -1
|
|
%e = sext i1 %c to i32
|
|
%r = add i32 %e, 42
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @sel_ifpos_fval_bigger(i32 %x) {
|
|
; CHECK-LABEL: sel_ifpos_fval_bigger:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: li 4, 42
|
|
; CHECK-NEXT: cmpwi 0, 3, -1
|
|
; CHECK-NEXT: li 3, 41
|
|
; CHECK-NEXT: isel 3, 3, 4, 1
|
|
; CHECK-NEXT: blr
|
|
%c = icmp sgt i32 %x, -1
|
|
%r = select i1 %c, i32 41, i32 42
|
|
ret i32 %r
|
|
}
|
|
|
|
; If negative...
|
|
|
|
define i32 @zext_ifneg(i32 %x) {
|
|
; CHECK-LABEL: zext_ifneg:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: srwi 3, 3, 31
|
|
; CHECK-NEXT: blr
|
|
%c = icmp slt i32 %x, 0
|
|
%r = zext i1 %c to i32
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @add_zext_ifneg(i32 %x) {
|
|
; CHECK-LABEL: add_zext_ifneg:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: srwi 3, 3, 31
|
|
; CHECK-NEXT: addi 3, 3, 41
|
|
; CHECK-NEXT: blr
|
|
%c = icmp slt i32 %x, 0
|
|
%e = zext i1 %c to i32
|
|
%r = add i32 %e, 41
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @sel_ifneg_tval_bigger(i32 %x) {
|
|
; CHECK-LABEL: sel_ifneg_tval_bigger:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: li 4, 41
|
|
; CHECK-NEXT: cmpwi 0, 3, 0
|
|
; CHECK-NEXT: li 3, 42
|
|
; CHECK-NEXT: isel 3, 3, 4, 0
|
|
; CHECK-NEXT: blr
|
|
%c = icmp slt i32 %x, 0
|
|
%r = select i1 %c, i32 42, i32 41
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @sext_ifneg(i32 %x) {
|
|
; CHECK-LABEL: sext_ifneg:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: srawi 3, 3, 31
|
|
; CHECK-NEXT: blr
|
|
%c = icmp slt i32 %x, 0
|
|
%r = sext i1 %c to i32
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @add_sext_ifneg(i32 %x) {
|
|
; CHECK-LABEL: add_sext_ifneg:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: srawi 3, 3, 31
|
|
; CHECK-NEXT: addi 3, 3, 42
|
|
; CHECK-NEXT: blr
|
|
%c = icmp slt i32 %x, 0
|
|
%e = sext i1 %c to i32
|
|
%r = add i32 %e, 42
|
|
ret i32 %r
|
|
}
|
|
|
|
define i32 @sel_ifneg_fval_bigger(i32 %x) {
|
|
; CHECK-LABEL: sel_ifneg_fval_bigger:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: li 4, 42
|
|
; CHECK-NEXT: cmpwi 0, 3, 0
|
|
; CHECK-NEXT: li 3, 41
|
|
; CHECK-NEXT: isel 3, 3, 4, 0
|
|
; CHECK-NEXT: blr
|
|
%c = icmp slt i32 %x, 0
|
|
%r = select i1 %c, i32 41, i32 42
|
|
ret i32 %r
|
|
}
|
|
|