[llvm] [DAG] visitEXTRACT_VECTOR_ELT - constant fold legal fp imm values (PR #74304)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 03:15:19 PST 2023


================
@@ -22243,6 +22243,19 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
   unsigned NumElts = VecVT.getVectorNumElements();
   unsigned VecEltBitWidth = VecVT.getScalarSizeInBits();
 
+  // See if the extracted element is constant, in which case fold it if its
+  // a legal fp immediate.
+  if (IndexC && ScalarVT.isFloatingPoint()) {
+    APInt EltMask = APInt::getOneBitSet(NumElts, IndexC->getZExtValue());
+    KnownBits KnownElt = DAG.computeKnownBits(VecOp, EltMask);
+    if (KnownElt.isConstant()) {
----------------
arsenm wrote:

Why is this fancy instead of just using dyn_cast<ConstantSDNode>?

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


More information about the llvm-commits mailing list