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

Kito Cheng via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 06:04:06 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))) {
----------------
kito-cheng wrote:

I just try another approach to prevent illegal type begin created during the process, also it not cause any other code gen change, otherwise I am really confused among LegalTypes/LegalDAG/LegalOperations...

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


More information about the llvm-commits mailing list