[DAGCombiner] Replace a hardcoded constant in visitZERO_EXTEND with a proper check...
authorCraig Topper <craig.topper@gmail.com>
Mon, 6 Apr 2020 02:26:15 +0000 (19:26 -0700)
committerCraig Topper <craig.topper@gmail.com>
Mon, 6 Apr 2020 03:35:57 +0000 (20:35 -0700)
This code is replacing a shift with a new shift on an extended type.
If the shift amount type can't represent the maximum shift amount
for the new type, the amount needs to be extended to a type that
can.

Previously, the code just hardcoded a check for 256 bits which
seems to have been an assumption that the original shift amount
was MVT::i8. But that seems more catered to a specific target
like X86 that uses i8 as its legal shift amount type. Other
targets may use different types.

This commit changes the code to look at the real type of the shift
amount and makes sure it has enough bits for the Log2 of the
new type. There are similar checks to this in SelectionDAGBuilder
and LegalizeIntegerTypes.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index 77fa5c7..0896858 100644 (file)
@@ -10326,7 +10326,7 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
     SDLoc DL(N);
 
     // Ensure that the shift amount is wide enough for the shifted value.
-    if (VT.getSizeInBits() >= 256)
+    if (Log2_32_Ceil(VT.getSizeInBits()) > ShAmt.getValueSizeInBits())
       ShAmt = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, ShAmt);
 
     return DAG.getNode(N0.getOpcode(), DL, VT,