Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -1544,6 +1544,16 @@ Known.Zero = Known2.Zero.reverseBits(); break; } + case ISD::BSWAP: { + SDValue Src = Op.getOperand(0); + APInt DemandedSrcBits = DemandedBits.byteSwap(); + if (SimplifyDemandedBits(Src, DemandedSrcBits, DemandedElts, Known2, TLO, + Depth + 1)) + return true; + Known.One = Known2.One.byteSwap(); + Known.Zero = Known2.Zero.byteSwap(); + break; + } case ISD::SIGN_EXTEND_INREG: { SDValue Op0 = Op.getOperand(0); EVT ExVT = cast(Op.getOperand(1))->getVT(); Index: llvm/test/CodeGen/AArch64/arm64-rev.ll =================================================================== --- llvm/test/CodeGen/AArch64/arm64-rev.ll +++ llvm/test/CodeGen/AArch64/arm64-rev.ll @@ -39,8 +39,8 @@ define i32 @test_rev_w_srl16(i16 %a) { ; CHECK-LABEL: test_rev_w_srl16: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: and w8, w0, #0xffff -; CHECK-NEXT: rev16 w0, w8 +; CHECK-NEXT: rev w8, w0 +; CHECK-NEXT: lsr w0, w8, #16 ; CHECK-NEXT: ret ; ; FALLBACK-LABEL: test_rev_w_srl16: @@ -60,7 +60,8 @@ ; CHECK-LABEL: test_rev_w_srl16_load: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ldrh w8, [x0] -; CHECK-NEXT: rev16 w0, w8 +; CHECK-NEXT: rev w8, w8 +; CHECK-NEXT: lsr w0, w8, #16 ; CHECK-NEXT: ret ; ; FALLBACK-LABEL: test_rev_w_srl16_load: @@ -106,8 +107,9 @@ define i64 @test_rev_x_srl32(i32 %a) { ; CHECK-LABEL: test_rev_x_srl32: ; CHECK: // %bb.0: // %entry -; CHECK-NEXT: mov w8, w0 -; CHECK-NEXT: rev32 x0, x8 +; CHECK-NEXT: // kill: def $w0 killed $w0 def $x0 +; CHECK-NEXT: rev x8, x0 +; CHECK-NEXT: lsr x0, x8, #32 ; CHECK-NEXT: ret ; ; FALLBACK-LABEL: test_rev_x_srl32: @@ -128,7 +130,8 @@ ; CHECK-LABEL: test_rev_x_srl32_load: ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ldr w8, [x0] -; CHECK-NEXT: rev32 x0, x8 +; CHECK-NEXT: rev x8, x8 +; CHECK-NEXT: lsr x0, x8, #32 ; CHECK-NEXT: ret ; ; FALLBACK-LABEL: test_rev_x_srl32_load: Index: llvm/test/CodeGen/AMDGPU/bswap.ll =================================================================== --- llvm/test/CodeGen/AMDGPU/bswap.ll +++ llvm/test/CodeGen/AMDGPU/bswap.ll @@ -732,7 +732,6 @@ ; VI-LABEL: missing_truncate_promote_bswap: ; VI: ; %bb.0: ; %bb ; VI-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) -; VI-NEXT: v_and_b32_e32 v0, 0xffff, v0 ; VI-NEXT: v_alignbit_b32 v1, v0, v0, 8 ; VI-NEXT: v_alignbit_b32 v0, v0, v0, 24 ; VI-NEXT: s_mov_b32 s4, 0xff00ff Index: llvm/test/CodeGen/X86/combine-bswap.ll =================================================================== --- llvm/test/CodeGen/X86/combine-bswap.ll +++ llvm/test/CodeGen/X86/combine-bswap.ll @@ -40,8 +40,7 @@ define i32 @test_demandedbits_bswap(i32 %a0) nounwind { ; X86-LABEL: test_demandedbits_bswap: ; X86: # %bb.0: -; X86-NEXT: movl $-16777216, %eax # imm = 0xFF000000 -; X86-NEXT: orl {{[0-9]+}}(%esp), %eax +; X86-NEXT: movl {{[0-9]+}}(%esp), %eax ; X86-NEXT: bswapl %eax ; X86-NEXT: andl $-65536, %eax # imm = 0xFFFF0000 ; X86-NEXT: retl @@ -49,7 +48,6 @@ ; X64-LABEL: test_demandedbits_bswap: ; X64: # %bb.0: ; X64-NEXT: movl %edi, %eax -; X64-NEXT: orl $-16777216, %eax # imm = 0xFF000000 ; X64-NEXT: bswapl %eax ; X64-NEXT: andl $-65536, %eax # imm = 0xFFFF0000 ; X64-NEXT: retq