[PATCH] D84332: [DAGCombiner] Fold sext_inreg of a masked load into a signed extended masked load
Sam Tebbs via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 24 09:04:52 PDT 2020
samtebbs updated this revision to Diff 280479.
samtebbs marked 2 inline comments as done and 2 inline comments as done.
samtebbs added a comment.
Simplify test and add extra checks to sext masked load generation.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D84332/new/
https://reviews.llvm.org/D84332
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/Thumb2/mve-masked-load.ll
llvm/test/CodeGen/Thumb2/sext-masked-load.ll
Index: llvm/test/CodeGen/Thumb2/sext-masked-load.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/sext-masked-load.ll
@@ -0,0 +1,19 @@
+; 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 arm_aapcs_vfpcc <4 x float> @foo_v4i16(<4 x i16>* nocapture readonly %pSrc, i32 %blockSize, <4 x i16> %a) {
+; CHECK-LABEL: foo_v4i16:
+; CHECK: @ %bb.0: @ %entry
+; CHECK-NEXT: vmovlb.s16 q0, q0
+; CHECK-NEXT: vpt.s32 lt, q0, zr
+; CHECK-NEXT: vldrht.s32 q0, [r0]
+; CHECK-NEXT: vcvt.f32.s32 q0, q0
+; CHECK-NEXT: bx lr
+entry:
+ %active.lane.mask = icmp slt <4 x i16> %a, zeroinitializer
+ %wide.masked.load = call <4 x i16> @llvm.masked.load.v4i16.p0v4i16(<4 x i16>* %pSrc, i32 2, <4 x i1> %active.lane.mask, <4 x i16> undef)
+ %0 = sitofp <4 x i16> %wide.masked.load to <4 x float>
+ ret <4 x float> %0
+}
+
+declare <4 x i16> @llvm.masked.load.v4i16.p0v4i16(<4 x i16>*, i32 immarg, <4 x i1>, <4 x i16>)
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/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<MaskedLoadSDNode>(N0)) {
+ if (ExtVT == Ld->getMemoryVT() && !LegalOperations &&
+ Ld->getExtensionType() != ISD::LoadExtType::SEXTLOAD && N0.hasOneUse() && TLI.isLoadExtLegal(ISD::SEXTLOAD, VT, ExtVT)) {
+ SDValue ExtMaskedLoad =
+ DAG.getMaskedLoad(VT, SDLoc(N), Ld->getChain(), Ld->getBasePtr(),
+ Ld->getOffset(), Ld->getMask(), Ld->getPassThru(),
+ ExtVT, Ld->getMemOperand(), Ld->getAddressingMode(),
+ ISD::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),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84332.280479.patch
Type: text/x-patch
Size: 3935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200724/e4e131fb/attachment.bin>
More information about the llvm-commits
mailing list