[llvm] [DAG] Reducing instructions by better legalization handling of AVGFLOORU for illegal data types (PR #99913)

Julius Alexandre via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 10:12:41 PDT 2024


================
@@ -9352,25 +9352,25 @@ SDValue TargetLowering::expandAVG(SDNode *N, SelectionDAG &DAG) const {
     }
   }
 
-  if (VT.isScalarInteger() && !isTypeLegal(VT)) {
-    SDValue UAddWithOverflow = DAG.getNode(ISD::UADDO, dl, 
-                                           DAG.getVTList(VT, MVT::i1), { RHS, LHS });
+  if (Opc == ISD::AVGFLOORU && VT.isScalarInteger() && !isTypeLegal(VT)) {
+    SDValue UAddWithOverflow =
+        DAG.getNode(ISD::UADDO, dl, DAG.getVTList(VT, MVT::i1), {RHS, LHS});
 
     SDValue Sum = UAddWithOverflow.getValue(0);
     SDValue Overflow = UAddWithOverflow.getValue(1);
 
     // Right shift the sum by 1
     SDValue One = DAG.getShiftAmountConstant(1, VT, dl);
     SDValue LShrVal = DAG.getNode(ISD::SRL, dl, VT, Sum, One);
-    
+
     // Creating the select instruction
-    SDValue ZeroOut = DAG.getConstant(0, dl, VT); 
-    SDValue ZeroExtOverflow = DAG.getNode(ISD::ZERO_EXTEND, dl, VT, Overflow);
-    SDValue OverflowShl = DAG.getNode(ISD::SHL, dl, VT, ZeroExtOverflow, 
-                                      DAG.getConstant(VT.getScalarSizeInBits() - 1, dl, VT)); 
-    SDValue SelectVal = DAG.getSelect(dl, VT, Overflow, OverflowShl, ZeroOut);
+    SDValue ZeroOut = DAG.getConstant(0, dl, VT);
----------------
medievalghoul wrote:

I make sure to remove this unused variable in the next commit i make, I didn't catch this at first

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


More information about the llvm-commits mailing list