@@ -735,8 +735,7 @@ SDOperand DAGCombiner::visitMUL(SDNode *N) {
735
735
736
736
// fold (mul c1, c2) -> c1*c2
737
737
if (N0C && N1C)
738
- return DAG.getConstant (N0C->getValue () * N1C->getValue (),
739
- N->getValueType (0 ));
738
+ return DAG.getConstant (N0C->getValue () * N1C->getValue (), VT);
740
739
// canonicalize constant to RHS
741
740
if (N0C && !N1C)
742
741
return DAG.getNode (ISD::MUL, VT, N1, N0);
@@ -748,9 +747,20 @@ SDOperand DAGCombiner::visitMUL(SDNode *N) {
748
747
return DAG.getNode (ISD::SUB, VT, DAG.getConstant (0 , VT), N0);
749
748
// fold (mul x, (1 << c)) -> x << c
750
749
if (N1C && isPowerOf2_64 (N1C->getValue ()))
751
- return DAG.getNode (ISD::SHL, N-> getValueType ( 0 ) , N0,
750
+ return DAG.getNode (ISD::SHL, VT , N0,
752
751
DAG.getConstant (Log2_64 (N1C->getValue ()),
753
752
TLI.getShiftAmountTy ()));
753
+ // fold (mul x, -(1 << c)) -> -(x << c) or (-x) << c
754
+ if (N1C && isPowerOf2_64 (-N1C->getSignExtended ())) {
755
+ // FIXME: If the input is something that is easily negated (e.g. a
756
+ // single-use add), we should put the negate there.
757
+ return DAG.getNode (ISD::SUB, VT, DAG.getConstant (0 , VT),
758
+ DAG.getNode (ISD::SHL, VT, N0,
759
+ DAG.getConstant (Log2_64 (-N1C->getSignExtended ()),
760
+ TLI.getShiftAmountTy ())));
761
+ }
762
+
763
+
754
764
// fold (mul (mul x, c1), c2) -> (mul x, c1*c2)
755
765
if (N1C && N0.getOpcode () == ISD::MUL) {
756
766
ConstantSDNode *N00C = dyn_cast<ConstantSDNode>(N0.getOperand (0 ));
0 commit comments