[llvm] [MIPS]Remove unnecessary SLL instructions on MIPS64el (PR #109386)

via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 22 19:42:08 PST 2024


================
@@ -1213,6 +1214,30 @@ static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG,
                      DAG.getConstant(SMSize, DL, MVT::i32));
 }
 
+static SDValue performSignExtendCombine(SDNode *N, SelectionDAG &DAG,
+                                        TargetLowering::DAGCombinerInfo &DCI,
+                                        const MipsSubtarget &Subtarget) {
+  SDValue N0 = N->getOperand(0);
+  EVT VT = N->getValueType(0);
+
+  //  $dst = sign_extend (xor (trunc $src), imm)
+  //  => $dst = sign_extend (trunc (xor $src, imm))
+  if (N0.getOpcode() == ISD::XOR &&
+      N0.getOperand(0).getOpcode() == ISD::TRUNCATE &&
+      N0.getOperand(1).getOpcode() == ISD::Constant) {
+    SDValue TruncateOperand = N0.getOperand(0).getOperand(0);
+    APInt Mask = N0.getConstantOperandAPInt(1).zext(VT.getSizeInBits());
+
+    SDValue Xor = DAG.getNode(ISD::XOR, SDLoc(N), VT, TruncateOperand,
+                              DAG.getTargetConstant(Mask, SDLoc(N), VT));
+    SDValue Truncate =
+        DAG.getNode(ISD::TRUNCATE, SDLoc(N), N0->getValueType(0), Xor);
----------------
yingopq wrote:

@wzssyqa The third parameter `N0->getValueType(0)` is the truncate's destination type, that you mentioned the code lacked. Through this Node we can truncate the fourth parameter `Xor` to type `N0->getValueType(0)`.
So I think this did not lack a imm. May I understand right?

https://github.com/llvm/llvm-project/pull/109386


More information about the llvm-commits mailing list