[DAG] matchRotateSub - set demanded bits to the shift amount type size, not the shift...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 26 Jul 2022 16:58:08 +0000 (17:58 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 26 Jul 2022 16:58:51 +0000 (17:58 +0100)
This should fix a report on D130251 of an assert due to a bitwidth mismatch in APInt::isSubSetOf

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index 21bad73..6548791 100644 (file)
@@ -7301,7 +7301,8 @@ static bool matchRotateSub(SDValue Pos, SDValue Neg, unsigned EltSize,
   unsigned MaskLoBits = 0;
   if (IsRotate && isPowerOf2_64(EltSize)) {
     unsigned Bits = Log2_64(EltSize);
-    APInt DemandedBits = APInt::getLowBitsSet(EltSize, Bits);
+    APInt DemandedBits =
+        APInt::getLowBitsSet(Neg.getScalarValueSizeInBits(), Bits);
     if (SDValue Inner =
             TLI.SimplifyMultipleUseDemandedBits(Neg, DemandedBits, DAG)) {
       Neg = Inner;
@@ -7321,7 +7322,8 @@ static bool matchRotateSub(SDValue Pos, SDValue Neg, unsigned EltSize,
   // affect Mask's demanded bits, just replace Pos with Pos'. These operations
   // are redundant for the purpose of the equality.
   if (MaskLoBits) {
-    APInt DemandedBits = APInt::getLowBitsSet(EltSize, MaskLoBits);
+    APInt DemandedBits =
+        APInt::getLowBitsSet(Pos.getScalarValueSizeInBits(), MaskLoBits);
     if (SDValue Inner =
             TLI.SimplifyMultipleUseDemandedBits(Pos, DemandedBits, DAG)) {
       Pos = Inner;