diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -12097,13 +12097,29 @@ SDNode *N, SDValue N0, ISD::LoadExtType ExtLoadType, ISD::NodeType ExtOpc) { - if (!N0.hasOneUse()) - return SDValue(); MaskedLoadSDNode *Ld = dyn_cast(N0); if (!Ld || Ld->getExtensionType() != ISD::NON_EXTLOAD) return SDValue(); + auto AllUsesCanBeReplaced = [&](SDValue V) { + for (SDNode::use_iterator UI = V->use_begin(), UE = V->use_end(); UI != UE; + ++UI) { + SDNode *User = *UI; + // Skip chain uses and the extension dag node N + if (UI.getUse().getResNo() != 0 || User == N) + continue; + // If all other uses of the load are just truncates we're fine to just + // truncate the extended type. + if (User->getOpcode() != ISD::TRUNCATE) + return false; + } + return true; + }; + + if (!AllUsesCanBeReplaced(N0)) + return SDValue(); + if (!TLI.isLoadExtLegalOrCustom(ExtLoadType, VT, Ld->getValueType(0))) return SDValue(); @@ -12630,9 +12646,8 @@ ISD::ZEXTLOAD, ISD::ZERO_EXTEND)) return foldedExt; - if (SDValue foldedExt = - tryToFoldExtOfMaskedLoad(DAG, TLI, VT, N, N0, ISD::ZEXTLOAD, - ISD::ZERO_EXTEND)) + if (SDValue foldedExt = tryToFoldExtOfMaskedLoad( + DAG, TLI, VT, N, N0, ISD::ZEXTLOAD, ISD::ZERO_EXTEND)) return foldedExt; // fold (zext (load x)) to multiple smaller zextloads. diff --git a/llvm/test/CodeGen/AArch64/sve-load-compare-store.ll b/llvm/test/CodeGen/AArch64/sve-load-compare-store.ll --- a/llvm/test/CodeGen/AArch64/sve-load-compare-store.ll +++ b/llvm/test/CodeGen/AArch64/sve-load-compare-store.ll @@ -6,9 +6,7 @@ ; CHECK: // %bb.0: // %entry ; CHECK-NEXT: ptrue p0.b ; CHECK-NEXT: ld1h { z0.s }, p0/z, [x0] -; CHECK-NEXT: mov z1.d, z0.d -; CHECK-NEXT: and z1.s, z1.s, #0xffff -; CHECK-NEXT: cmphs p0.s, p0/z, z1.s, #0 +; CHECK-NEXT: cmphs p0.s, p0/z, z0.s, #0 ; CHECK-NEXT: st1b { z0.s }, p0, [x1] ; CHECK-NEXT: ret entry: diff --git a/llvm/unnecessary_inversion.isel.txt b/llvm/unnecessary_inversion.isel.txt new file mode 100644 --- /dev/null +++ b/llvm/unnecessary_inversion.isel.txt @@ -0,0 +1 @@ +/home/benmax01/git/llvm-project/build/bin/llc: error: /home/benmax01/git/llvm-project/build/bin/llc: unnecessary_inversion.ll: error: Could not open input file: No such file or directory