Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -11125,6 +11125,22 @@ return SDValue(N, 0); // Return N so it doesn't get rechecked! } + // fold (sext_inreg (masked_load x)) -> (sext_masked_load x) + // ignore it if the masked load is already sign extended + if (MaskedLoadSDNode *Ld = dyn_cast(N0)) { + if (ExtVT == Ld->getMemoryVT() && !LegalOperations && + Ld->getExtensionType() != ISD::LoadExtType::SEXTLOAD) { + SDValue ExtMaskedLoad = + DAG.getMaskedLoad(VT, SDLoc(N), Ld->getChain(), Ld->getBasePtr(), + Ld->getOffset(), Ld->getMask(), Ld->getPassThru(), + ExtVT, Ld->getMemOperand(), Ld->getAddressingMode(), + ISD::LoadExtType::SEXTLOAD, Ld->isExpandingLoad()); + CombineTo(N, ExtMaskedLoad); + CombineTo(N0.getNode(), ExtMaskedLoad, ExtMaskedLoad.getValue(1)); + return SDValue(N, 0); // Return N so it doesn't get rechecked! + } + } + // Form (sext_inreg (bswap >> 16)) or (sext_inreg (rotl (bswap) 16)) if (ExtVTBits <= 16 && N0.getOpcode() == ISD::OR) { if (SDValue BSwap = MatchBSwapHWordLow(N0.getNode(), N0.getOperand(0), Index: llvm/test/CodeGen/Thumb2/mve-masked-load.ll =================================================================== --- llvm/test/CodeGen/Thumb2/mve-masked-load.ll +++ llvm/test/CodeGen/Thumb2/mve-masked-load.ll @@ -2148,11 +2148,11 @@ ; CHECK-LE-NEXT: .vsave {d8, d9} ; CHECK-LE-NEXT: vpush {d8, d9} ; CHECK-LE-NEXT: vpt.s32 gt, q0, zr -; CHECK-LE-NEXT: vldrht.u32 q4, [r0] +; CHECK-LE-NEXT: vldrht.s32 q4, [r0] ; CHECK-LE-NEXT: vmov r0, r1, d8 ; CHECK-LE-NEXT: vmov r2, r3, d9 ; CHECK-LE-NEXT: bl foo -; CHECK-LE-NEXT: vmovlb.s16 q0, q4 +; CHECK-LE-NEXT: vmov q0, q4 ; CHECK-LE-NEXT: vpop {d8, d9} ; CHECK-LE-NEXT: pop {r7, pc} ; @@ -2164,13 +2164,12 @@ ; CHECK-BE-NEXT: vpush {d8, d9} ; CHECK-BE-NEXT: vrev64.32 q1, q0 ; CHECK-BE-NEXT: vpt.s32 gt, q1, zr -; CHECK-BE-NEXT: vldrht.u32 q4, [r0] -; CHECK-BE-NEXT: vrev64.32 q0, q4 -; CHECK-BE-NEXT: vmov r1, r0, d0 -; CHECK-BE-NEXT: vmov r3, r2, d1 +; CHECK-BE-NEXT: vldrht.s32 q0, [r0] +; CHECK-BE-NEXT: vrev64.32 q4, q0 +; CHECK-BE-NEXT: vmov r1, r0, d8 +; CHECK-BE-NEXT: vmov r3, r2, d9 ; CHECK-BE-NEXT: bl foo -; CHECK-BE-NEXT: vmovlb.s16 q1, q4 -; CHECK-BE-NEXT: vrev64.32 q0, q1 +; CHECK-BE-NEXT: vmov q0, q4 ; CHECK-BE-NEXT: vpop {d8, d9} ; CHECK-BE-NEXT: pop {r7, pc} entry: Index: llvm/test/CodeGen/Thumb2/sext-masked-load.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/Thumb2/sext-masked-load.ll @@ -0,0 +1,37 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve.fp -verify-machineinstrs -tail-predication=enabled -o - %s | FileCheck %s +define void @arm_q15_to_float(i16* nocapture readonly %pSrc, float* nocapture %pDst, i32 %blockSize) { +; CHECK-LABEL: arm_q15_to_float: +; CHECK: vldrw.u32 q1, [r3] +; CHECK-NEXT: vdup.32 q2, r2 +; CHECK-NEXT: vpt.u32 cs, q2, q1 +; CHECK-NEXT: vldrht.s32 q1, [r0] +; CHECK-NEXT: vmov.i32 q0, #0x38000000 +; CHECK-NEXT: vcvt.f32.s32 q1, q1 +; CHECK-NEXT: vmul.f32 q0, q1, q0 +entry: + %cmp.not5 = icmp eq i32 %blockSize, 0 + br i1 %cmp.not5, label %return, label %body + +body: + %trip.count.minus.1 = add i32 %blockSize, -1 + %next.gep = getelementptr i16, i16* %pSrc, i32 0 + %next.gep15 = getelementptr float, float* %pDst, i32 0 + %active.lane.mask = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 0, i32 %trip.count.minus.1) + %0 = bitcast i16* %next.gep to <4 x i16>* + %wide.masked.load = call <4 x i16> @llvm.masked.load.v4i16.p0v4i16(<4 x i16>* %0, i32 2, <4 x i1> %active.lane.mask, <4 x i16> undef) + %1 = sitofp <4 x i16> %wide.masked.load to <4 x float> + %2 = fmul fast <4 x float> %1, + %3 = bitcast float* %next.gep15 to <4 x float>* + call void @llvm.masked.store.v4f32.p0v4f32(<4 x float> %2, <4 x float>* %3, i32 4, <4 x i1> %active.lane.mask) + br label %return + +return: + ret void +} + +declare <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32, i32) + +declare <4 x i16> @llvm.masked.load.v4i16.p0v4i16(<4 x i16>*, i32 immarg, <4 x i1>, <4 x i16>) + +declare void @llvm.masked.store.v4f32.p0v4f32(<4 x float>, <4 x float>*, i32 immarg, <4 x i1>)