[PATCH] D103323: [DAGCombiner] Add support for mulhi const folding in DAGCombiner
David Stuttard via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 28 09:14:09 PDT 2021
dstuttard updated this revision to Diff 348550.
dstuttard added a comment.
Thanks for reviews.
Made suggested changes.
I'll add some test cases as well - but I'm off for a few days. I'll do it on return.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103323/new/
https://reviews.llvm.org/D103323
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5085,6 +5085,18 @@
if (!C2.getBoolValue())
break;
return C1.srem(C2);
+ case ISD::MULHS: {
+ unsigned FullWidth = C1.getBitWidth() * 2;
+ APInt C1Ext = C1.sext(FullWidth);
+ APInt C2Ext = C2.sext(FullWidth);
+ return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth());
+ }
+ case ISD::MULHU: {
+ unsigned FullWidth = C1.getBitWidth() * 2;
+ APInt C1Ext = C1.zext(FullWidth);
+ APInt C2Ext = C2.zext(FullWidth);
+ return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth());
+ }
}
return llvm::None;
}
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -4450,6 +4450,11 @@
return DAG.getConstant(0, DL, VT);
}
+ // fold (mulhs c1, c2)
+ if (SDValue C =
+ DAG.FoldConstantArithmetic(ISD::MULHS, SDLoc(N), VT, {N0, N1}))
+ return C;
+
// fold (mulhs x, 0) -> 0
if (isNullConstant(N1))
return N1;
@@ -4498,6 +4503,11 @@
return DAG.getConstant(0, DL, VT);
}
+ // fold (mulhu c1, c2)
+ if (SDValue C =
+ DAG.FoldConstantArithmetic(ISD::MULHU, SDLoc(N), VT, {N0, N1}))
+ return C;
+
// fold (mulhu x, 0) -> 0
if (isNullConstant(N1))
return N1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103323.348550.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210528/ab7c5a10/attachment.bin>
More information about the llvm-commits
mailing list