Skip to content

Commit aa33570

Browse files
committed
LoongArch: Fix wrong LSX FP vector negation
We expanded (neg x) to (minus const0 x) for LSX FP vectors, this is wrong because -0.0 is not 0 - 0.0. This causes some Python tests to fail when Python is built with LSX enabled. Use the vbitrevi.{d/w} instructions to simply reverse the sign bit instead. We are already doing this for LASX and now we can unify them into simd.md. gcc/ChangeLog: * config/loongarch/lsx.md (neg<mode:FLSX>2): Remove the incorrect expand. * config/loongarch/simd.md (simdfmt_as_i): New define_mode_attr. (elmsgnbit): Likewise. (neg<mode:FVEC>2): New define_insn. * config/loongarch/lasx.md (negv4df2, negv8sf2): Remove as they are now instantiated in simd.md.
1 parent 829b263 commit aa33570

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

gcc/config/loongarch/lasx.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,22 +3028,6 @@
30283028
[(set_attr "type" "simd_logic")
30293029
(set_attr "mode" "V8SF")])
30303030

3031-
(define_insn "negv4df2"
3032-
[(set (match_operand:V4DF 0 "register_operand" "=f")
3033-
(neg:V4DF (match_operand:V4DF 1 "register_operand" "f")))]
3034-
"ISA_HAS_LASX"
3035-
"xvbitrevi.d\t%u0,%u1,63"
3036-
[(set_attr "type" "simd_logic")
3037-
(set_attr "mode" "V4DF")])
3038-
3039-
(define_insn "negv8sf2"
3040-
[(set (match_operand:V8SF 0 "register_operand" "=f")
3041-
(neg:V8SF (match_operand:V8SF 1 "register_operand" "f")))]
3042-
"ISA_HAS_LASX"
3043-
"xvbitrevi.w\t%u0,%u1,31"
3044-
[(set_attr "type" "simd_logic")
3045-
(set_attr "mode" "V8SF")])
3046-
30473031
(define_insn "xvfmadd<mode>4"
30483032
[(set (match_operand:FLASX 0 "register_operand" "=f")
30493033
(fma:FLASX (match_operand:FLASX 1 "register_operand" "f")

gcc/config/loongarch/lsx.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -728,17 +728,6 @@
728728
DONE;
729729
})
730730

731-
(define_expand "neg<mode>2"
732-
[(set (match_operand:FLSX 0 "register_operand")
733-
(neg:FLSX (match_operand:FLSX 1 "register_operand")))]
734-
"ISA_HAS_LSX"
735-
{
736-
rtx reg = gen_reg_rtx (<MODE>mode);
737-
emit_move_insn (reg, CONST0_RTX (<MODE>mode));
738-
emit_insn (gen_sub<mode>3 (operands[0], reg, operands[1]));
739-
DONE;
740-
})
741-
742731
(define_expand "lsx_vrepli<mode>"
743732
[(match_operand:ILSX 0 "register_operand")
744733
(match_operand 1 "const_imm10_operand")]

gcc/config/loongarch/simd.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,21 @@
8585
(define_mode_attr simdifmt_for_f [(V2DF "l") (V4DF "l")
8686
(V4SF "w") (V8SF "w")])
8787

88+
;; Suffix for integer mode in LSX or LASX instructions to operating FP
89+
;; vectors using integer vector operations.
90+
(define_mode_attr simdfmt_as_i [(V2DF "d") (V4DF "d")
91+
(V4SF "w") (V8SF "w")])
92+
8893
;; Size of vector elements in bits.
8994
(define_mode_attr elmbits [(V2DI "64") (V4DI "64")
9095
(V4SI "32") (V8SI "32")
9196
(V8HI "16") (V16HI "16")
9297
(V16QI "8") (V32QI "8")])
9398

99+
;; The index of sign bit in FP vector elements.
100+
(define_mode_attr elmsgnbit [(V2DF "63") (V4DF "63")
101+
(V4SF "31") (V8SF "31")])
102+
94103
;; This attribute is used to form an immediate operand constraint using
95104
;; "const_<bitimm>_operand".
96105
(define_mode_attr bitimm [(V16QI "uimm3") (V32QI "uimm3")
@@ -457,6 +466,15 @@
457466
DONE;
458467
})
459468

469+
;; FP negation.
470+
(define_insn "neg<mode>2"
471+
[(set (match_operand:FVEC 0 "register_operand" "=f")
472+
(neg:FVEC (match_operand:FVEC 1 "register_operand" "f")))]
473+
""
474+
"<x>vbitrevi.<simdfmt_as_i>\t%<wu>0,%<wu>1,<elmsgnbit>"
475+
[(set_attr "type" "simd_logic")
476+
(set_attr "mode" "<MODE>")])
477+
460478
; The LoongArch SX Instructions.
461479
(include "lsx.md")
462480

0 commit comments

Comments
 (0)