[llvm] [DAGCombiner] Allow tryToFoldExtOfLoad to use a sextload for zext nneg. (PR #81714)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 16 08:06:51 PST 2024
================
@@ -13154,20 +13154,41 @@ static SDValue tryToFoldExtOfExtload(SelectionDAG &DAG, DAGCombiner &Combiner,
// fold ([s|z]ext (load x)) -> ([s|z]ext (truncate ([s|z]extload x)))
// Only generate vector extloads when 1) they're legal, and 2) they are
-// deemed desirable by the target.
+// deemed desirable by the target. NonNegZExt can be set to true if a zero
+// extend has the nonneg flag to allow use of sextload if profitable.
static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
const TargetLowering &TLI, EVT VT,
bool LegalOperations, SDNode *N, SDValue N0,
ISD::LoadExtType ExtLoadType,
- ISD::NodeType ExtOpc) {
+ ISD::NodeType ExtOpc,
+ bool NonNegZExt = false) {
+ if (!ISD::isNON_EXTLoad(N0.getNode()) || !ISD::isUNINDEXEDLoad(N0.getNode()))
+ return {};
+
+ // If this is zext nneg, see if it would make sense to treat it as a sext.
+ if (NonNegZExt) {
+ assert(ExtLoadType == ISD::ZEXTLOAD && ExtOpc == ISD::ZERO_EXTEND &&
+ "Unexpected load type or opcode");
+ for (SDNode::use_iterator UI = N0->use_begin(), UE = N0->use_end();
+ UI != UE; ++UI) {
+ SDNode *User = *UI;
----------------
nikic wrote:
```suggestion
for (SDNode *User : N0->uses()) {
```
I think?
https://github.com/llvm/llvm-project/pull/81714
More information about the llvm-commits
mailing list