[PATCH] D103323: [DAGCombiner] Add support for mulhi const folding in DAGCombiner
David Stuttard via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 17 01:14:08 PDT 2021
dstuttard updated this revision to Diff 352637.
dstuttard added a comment.
Updating for review comments.
Tests still to be added...
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
@@ -5081,6 +5081,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
@@ -4451,6 +4451,10 @@
return DAG.getConstant(0, DL, VT);
}
+ // fold (mulhs c1, c2)
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::MULHS, DL, VT, {N0, N1}))
+ return C;
+
// fold (mulhs x, 0) -> 0
if (isNullConstant(N1))
return N1;
@@ -4499,6 +4503,10 @@
return DAG.getConstant(0, DL, VT);
}
+ // fold (mulhu c1, c2)
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::MULHU, DL, 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.352637.patch
Type: text/x-patch
Size: 1554 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210617/991fcf44/attachment.bin>
More information about the llvm-commits
mailing list