Craig Topper 440c4b705a [SelectionDAG][RISCV][ARM][PowerPC][X86][WebAssembly] Change default abs expansion to use sra (X, size(X)-1); sub (xor (X, Y), Y).
Previous we used sra (X, size(X)-1); xor (add (X, Y), Y).

By placing sub at the end, we allow RISCV to combine sign_extend_inreg
with it to form subw.

Some X86 tests for Z - abs(X) seem to have improved as well.

Other targets look to be a wash.

I had to modify ARM's abs matching code to match from sub instead of
xor. Maybe instead ISD::ABS should be made legal. I'll try that in
parallel to this patch.

This is an alternative to D119099 which was focused on RISCV only.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D119171
2022-02-20 21:11:23 -08:00

27 lines
782 B
LLVM

; RUN: llc < %s -mtriple=wasm32-unknown-unknown | FileCheck %s
; Regression test for PR41149.
define void @mod() {
; CHECK-LABEL: mod:
; CHECK-NEXT: .functype mod () -> ()
; CHECK: local.get 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32.load8_s 0
; CHECK-NEXT: local.tee 0
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32.const 31
; CHECK-NEXT: i32.shr_s
; CHECK-NEXT: local.tee 0
; CHECK-NEXT: i32.xor
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32.sub
; CHECK-NEXT: i32.store8 0
%tmp = load <4 x i8>, <4 x i8>* undef
%tmp2 = icmp slt <4 x i8> %tmp, zeroinitializer
%tmp3 = sub <4 x i8> zeroinitializer, %tmp
%tmp4 = select <4 x i1> %tmp2, <4 x i8> %tmp3, <4 x i8> %tmp
store <4 x i8> %tmp4, <4 x i8>* undef
ret void
}