Index: lib/Target/Mips/MicroMipsInstrInfo.td =================================================================== --- lib/Target/Mips/MicroMipsInstrInfo.td +++ lib/Target/Mips/MicroMipsInstrInfo.td @@ -1127,6 +1127,8 @@ def : MipsPat<(i32 (extloadi16 addr:$src)), (LHu_MM addr:$src)>, ISA_MICROMIPS; + def : MipsPat<(bswap GPR32:$rt), (ROTR_MM (WSBH_MM GPR32:$rt), 16)>, + ISA_MICROMIPS; } def : MipsPat<(MipsTailCall (iPTR tglobaladdr:$dst)), Index: lib/Target/Mips/Mips64InstrInfo.td =================================================================== --- lib/Target/Mips/Mips64InstrInfo.td +++ lib/Target/Mips/Mips64InstrInfo.td @@ -728,7 +728,7 @@ (SLL64_64 GPR64:$src)>; // bswap MipsPattern -def : MipsPat<(bswap GPR64:$rt), (DSHD (DSBH GPR64:$rt))>; +def : MipsPat<(bswap GPR64:$rt), (DSHD (DSBH GPR64:$rt))>, ISA_MIPS64R2; // Carry pattern let AdditionalPredicates = [NotInMicroMips] in { Index: lib/Target/Mips/MipsInstrInfo.td =================================================================== --- lib/Target/Mips/MipsInstrInfo.td +++ lib/Target/Mips/MipsInstrInfo.td @@ -3027,10 +3027,10 @@ defm : SetgtPats; defm : SetgePats; defm : SetgeImmPats; -} -// bswap pattern -def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>; + // bswap pattern + def : MipsPat<(bswap GPR32:$rt), (ROTR (WSBH GPR32:$rt), 16)>, ISA_MIPS32R2; +} // Load halfword/word patterns. let AddedComplexity = 40 in { Index: test/CodeGen/Mips/2008-08-08-bswap.ll =================================================================== --- test/CodeGen/Mips/2008-08-08-bswap.ll +++ /dev/null @@ -1,15 +0,0 @@ -; DISABLED: llc < %s | grep wsbw | count 1 -; RUN: false -; XFAIL: * - - -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64" -target triple = "psp" - -define i32 @__bswapsi2(i32 %u) nounwind { -entry: - tail call i32 @llvm.bswap.i32( i32 %u ) ; :0 [#uses=1] - ret i32 %0 -} - -declare i32 @llvm.bswap.i32(i32) nounwind readnone Index: test/CodeGen/Mips/bswap.ll =================================================================== --- test/CodeGen/Mips/bswap.ll +++ test/CodeGen/Mips/bswap.ll @@ -1,4 +1,5 @@ ; RUN: llc < %s -march=mipsel -mcpu=mips32r2 | FileCheck %s -check-prefix=MIPS32 +; RUN: llc < %s -mtriple=mipsel-mti-linux-gnu -mcpu=mips32r2 -mattr=+micromips | FileCheck %s -check-prefix=MM ; RUN: llc < %s -march=mips64el -mcpu=mips64r2 | FileCheck %s -check-prefix=MIPS64 ; RUN: llc < %s -mtriple=mipsel-linux-gnu -march=mipsel -mcpu=mips32r2 -mattr=+mips16 | FileCheck %s -check-prefix=MIPS16 @@ -8,6 +9,10 @@ ; MIPS32: wsbh $[[R0:[0-9]+]] ; MIPS32: rotr ${{[0-9]+}}, $[[R0]], 16 +; MM-LABEL: bswap32: +; MM: wsbh $[[R0:[0-9]+]] +; MM: rotr ${{[0-9]+}}, $[[R0]], 16 + ; MIPS64-LABEL: bswap32: ; MIPS64: wsbh $[[R0:[0-9]+]] ; MIPS64: rotr ${{[0-9]+}}, $[[R0]], 16 @@ -37,6 +42,12 @@ ; MIPS32: wsbh $[[R0:[0-9]+]] ; MIPS32: rotr ${{[0-9]+}}, $[[R0]], 16 +; MM-LABEL: bswap64: +; MM: wsbh $[[R0:[0-9]+]] +; MM: rotr ${{[0-9]+}}, $[[R0]], 16 +; MM: wsbh $[[R0:[0-9]+]] +; MM: rotr ${{[0-9]+}}, $[[R0]], 16 + ; MIPS64-LABEL: bswap64: ; MIPS64: dsbh $[[R0:[0-9]+]] ; MIPS64: dshd ${{[0-9]+}}, $[[R0]] @@ -81,6 +92,16 @@ ; MIPS32-DAG: wsbh $[[R0:[0-9]+]] ; MIPS32-DAG: rotr ${{[0-9]+}}, $[[R0]], 16 +; MM-LABEL: bswapv4i32: +; MM-DAG: wsbh $[[R0:[0-9]+]] +; MM-DAG: rotr ${{[0-9]+}}, $[[R0]], 16 +; MM-DAG: wsbh $[[R0:[0-9]+]] +; MM-DAG: rotr ${{[0-9]+}}, $[[R0]], 16 +; MM-DAG: wsbh $[[R0:[0-9]+]] +; MM-DAG: rotr ${{[0-9]+}}, $[[R0]], 16 +; MM-DAG: wsbh $[[R0:[0-9]+]] +; MM-DAG: rotr ${{[0-9]+}}, $[[R0]], 16 + ; MIPS64-LABEL: bswapv4i32: ; MIPS64-DAG: wsbh $[[R0:[0-9]+]] ; MIPS64-DAG: rotr ${{[0-9]+}}, $[[R0]], 16