[llvm] [DAG] Fix illegal type in srl(bitcast(build_vector)) fold (PR #205074)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 21:51:04 PDT 2026


================
@@ -11694,11 +11694,15 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
       EVT BVVT = BV.getValueType();
       unsigned EltSizeInBits = BVVT.getScalarSizeInBits();
       unsigned NumElts = BVVT.getVectorNumElements();
-      if (N1C->getZExtValue() == (NumElts - 1) * EltSizeInBits) {
+      EVT IntEltVT = EVT::getIntegerVT(*DAG.getContext(), EltSizeInBits);
+      // This fold builds a zext/trunc through IntEltVT. In the last DAG combine
+      // new nodes are legalized at once, so only do it there if IntEltVT is
+      // legal. Earlier combines are legalized again later.
+      if (N1C->getZExtValue() == (NumElts - 1) * EltSizeInBits &&
+          (!LegalDAG || TLI.isTypeLegal(IntEltVT))) {
----------------
topperc wrote:

I think we should probably use LegalTypes not LegalDAG here. DAGCombiner isn't supposed to create illegal types between LegalTypes and LegalDAG.

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


More information about the llvm-commits mailing list