From: Craig Topper Date: Mon, 6 Apr 2020 02:26:15 +0000 (-0700) Subject: [DAGCombiner] Replace a hardcoded constant in visitZERO_EXTEND with a proper check... X-Git-Tag: llvmorg-12-init~10011 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=586c051a27070fc7fa3b04f220ed2b3e73c685b7;p=platform%2Fupstream%2Fllvm.git [DAGCombiner] Replace a hardcoded constant in visitZERO_EXTEND with a proper check for the condition its trying to protect. 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. --- diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 77fa5c7..0896858 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -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,