[DAGCombine] Check zext legality in zext-extract-extend combine
authorPeter Waller <peter.waller@arm.com>
Tue, 9 Aug 2022 15:13:50 +0000 (15:13 +0000)
committerTobias Hieta <tobias@hieta.se>
Tue, 16 Aug 2022 06:29:55 +0000 (08:29 +0200)
Discussed in D131503.

Fix to D130782.

(cherry picked from commit 898699831b5490d88b993593e5cb415fb2d1983a)

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index 8d465b9520de039309d943e5a6ff011cea8a6402..74ee0bdfbf421d738ee36e6f1019dd2f6f092348 100644 (file)
@@ -6360,7 +6360,8 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
     SDValue Extendee = Ext->getOperand(0);
 
     unsigned ScalarWidth = Extendee.getValueType().getScalarSizeInBits();
-    if (N1C->getAPIntValue().isMask(ScalarWidth)) {
+    if (N1C->getAPIntValue().isMask(ScalarWidth) &&
+        (!LegalOperations || TLI.isOperationLegal(ISD::ZERO_EXTEND, ExtVT))) {
       //    (and (extract_subvector (zext|anyext|sext v) _) iN_mask)
       // => (extract_subvector (iN_zeroext v))
       SDValue ZeroExtExtendee =