[llvm] e1aa162 - [Mips] Use ANDi in for zero-extend in subword atomic umax/umin for both r2 and pre-R2 (#89881)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 24 07:31:55 PDT 2024
Author: yingopq
Date: 2024-04-24T22:31:51+08:00
New Revision: e1aa16299f626317068c3d99e035d447145353c7
URL: https://github.com/llvm/llvm-project/commit/e1aa16299f626317068c3d99e035d447145353c7
DIFF: https://github.com/llvm/llvm-project/commit/e1aa16299f626317068c3d99e035d447145353c7.diff
LOG: [Mips] Use ANDi in for zero-extend in subword atomic umax/umin for both r2 and pre-R2 (#89881)
About unsigned max/min, ANDi is available for all ISA revisions in
extend before slt insn.
So that we can reduce one instruction.
Added:
Modified:
llvm/lib/Target/Mips/MipsExpandPseudo.cpp
llvm/test/CodeGen/Mips/atomic-min-max.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
index d33852a04baf0d..199474fbd82d75 100644
--- a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
+++ b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
@@ -479,13 +479,13 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
BuildMI(loopMBB, DL, TII->get(Mips::SRAV), StoreVal)
.addReg(OldVal)
.addReg(ShiftAmnt);
- if (STI->hasMips32r2() && !IsUnsigned) {
- BuildMI(loopMBB, DL, TII->get(SEOp), StoreVal).addReg(StoreVal);
- } else if (STI->hasMips32r2() && IsUnsigned) {
+ if (IsUnsigned) {
const unsigned OpMask = SEOp == Mips::SEH ? 0xffff : 0xff;
BuildMI(loopMBB, DL, TII->get(Mips::ANDi), StoreVal)
.addReg(StoreVal)
.addImm(OpMask);
+ } else if (STI->hasMips32r2()) {
+ BuildMI(loopMBB, DL, TII->get(SEOp), StoreVal).addReg(StoreVal);
} else {
const unsigned ShiftImm = SEOp == Mips::SEH ? 16 : 24;
const unsigned SROp = IsUnsigned ? Mips::SRL : Mips::SRA;
diff --git a/llvm/test/CodeGen/Mips/atomic-min-max.ll b/llvm/test/CodeGen/Mips/atomic-min-max.ll
index 2f07d70808c16a..3d3225509d1ae1 100644
--- a/llvm/test/CodeGen/Mips/atomic-min-max.ll
+++ b/llvm/test/CodeGen/Mips/atomic-min-max.ll
@@ -2156,8 +2156,7 @@ define i16 @test_umax_16(ptr nocapture %ptr, i16 signext %val) {
; MIPS32-NEXT: # =>This Inner Loop Header: Depth=1
; MIPS32-NEXT: ll $2, 0($6)
; MIPS32-NEXT: srav $4, $2, $10
-; MIPS32-NEXT: sll $4, $4, 16
-; MIPS32-NEXT: srl $4, $4, 16
+; MIPS32-NEXT: andi $4, $4, 65535
; MIPS32-NEXT: or $1, $zero, $4
; MIPS32-NEXT: sllv $4, $4, $10
; MIPS32-NEXT: sltu $5, $4, $7
@@ -2695,8 +2694,7 @@ define i16 @test_umin_16(ptr nocapture %ptr, i16 signext %val) {
; MIPS32-NEXT: # =>This Inner Loop Header: Depth=1
; MIPS32-NEXT: ll $2, 0($6)
; MIPS32-NEXT: srav $4, $2, $10
-; MIPS32-NEXT: sll $4, $4, 16
-; MIPS32-NEXT: srl $4, $4, 16
+; MIPS32-NEXT: andi $4, $4, 65535
; MIPS32-NEXT: or $1, $zero, $4
; MIPS32-NEXT: sllv $4, $4, $10
; MIPS32-NEXT: sltu $5, $4, $7
@@ -4313,8 +4311,7 @@ define i8 @test_umax_8(ptr nocapture %ptr, i8 signext %val) {
; MIPS32-NEXT: # =>This Inner Loop Header: Depth=1
; MIPS32-NEXT: ll $2, 0($6)
; MIPS32-NEXT: srav $4, $2, $10
-; MIPS32-NEXT: sll $4, $4, 24
-; MIPS32-NEXT: srl $4, $4, 24
+; MIPS32-NEXT: andi $4, $4, 255
; MIPS32-NEXT: or $1, $zero, $4
; MIPS32-NEXT: sllv $4, $4, $10
; MIPS32-NEXT: sltu $5, $4, $7
@@ -4852,8 +4849,7 @@ define i8 @test_umin_8(ptr nocapture %ptr, i8 signext %val) {
; MIPS32-NEXT: # =>This Inner Loop Header: Depth=1
; MIPS32-NEXT: ll $2, 0($6)
; MIPS32-NEXT: srav $4, $2, $10
-; MIPS32-NEXT: sll $4, $4, 24
-; MIPS32-NEXT: srl $4, $4, 24
+; MIPS32-NEXT: andi $4, $4, 255
; MIPS32-NEXT: or $1, $zero, $4
; MIPS32-NEXT: sllv $4, $4, $10
; MIPS32-NEXT: sltu $5, $4, $7
More information about the llvm-commits
mailing list