Index: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -327,7 +327,8 @@ // integer mul followed by a sext. if (SExtInst *Op0Conv = dyn_cast(Op0)) { // (mul (sext x), cst) --> (sext (mul x, cst')) - if (ConstantInt *Op1C = dyn_cast(Op1)) { + Constant *Op1C; + if (match(Op1, m_Constant(Op1C))) { if (Op0Conv->hasOneUse()) { Constant *CI = ConstantExpr::getTrunc(Op1C, Op0Conv->getOperand(0)->getType()); @@ -363,7 +364,8 @@ // integer mul followed by a zext. if (auto *Op0Conv = dyn_cast(Op0)) { // (mul (zext x), cst) --> (zext (mul x, cst')) - if (ConstantInt *Op1C = dyn_cast(Op1)) { + Constant *Op1C; + if (match(Op1, m_Constant(Op1C))) { if (Op0Conv->hasOneUse()) { Constant *CI = ConstantExpr::getTrunc(Op1C, Op0Conv->getOperand(0)->getType()); Index: test/Transforms/InstCombine/sink-zext.ll =================================================================== --- test/Transforms/InstCombine/sink-zext.ll +++ test/Transforms/InstCombine/sink-zext.ll @@ -214,8 +214,8 @@ define <2 x i64> @test8_splat(<2 x i32> %V) { ; CHECK-LABEL: @test8_splat( ; CHECK-NEXT: [[ASHR:%.*]] = ashr <2 x i32> [[V:%.*]], -; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i32> [[ASHR]] to <2 x i64> -; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i64> [[SEXT]], +; CHECK-NEXT: [[MULCONV:%.*]] = mul nsw <2 x i32> [[ASHR]], +; CHECK-NEXT: [[MUL:%.*]] = sext <2 x i32> [[MULCONV]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[MUL]] ; %ashr = ashr <2 x i32> %V, @@ -227,8 +227,8 @@ define <2 x i64> @test8_vec(<2 x i32> %V) { ; CHECK-LABEL: @test8_vec( ; CHECK-NEXT: [[ASHR:%.*]] = ashr <2 x i32> [[V:%.*]], -; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i32> [[ASHR]] to <2 x i64> -; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i64> [[SEXT]], +; CHECK-NEXT: [[MULCONV:%.*]] = mul nsw <2 x i32> [[ASHR]], +; CHECK-NEXT: [[MUL:%.*]] = sext <2 x i32> [[MULCONV]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[MUL]] ; %ashr = ashr <2 x i32> %V, @@ -240,8 +240,8 @@ define <2 x i64> @test8_vec2(<2 x i32> %V) { ; CHECK-LABEL: @test8_vec2( ; CHECK-NEXT: [[ASHR:%.*]] = ashr <2 x i32> [[V:%.*]], -; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i32> [[ASHR]] to <2 x i64> -; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i64> [[SEXT]], +; CHECK-NEXT: [[MULCONV:%.*]] = mul nsw <2 x i32> [[ASHR]], +; CHECK-NEXT: [[MUL:%.*]] = sext <2 x i32> [[MULCONV]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[MUL]] ; %ashr = ashr <2 x i32> %V, @@ -266,8 +266,8 @@ define <2 x i64> @test9_splat(<2 x i32> %V) { ; CHECK-LABEL: @test9_splat( ; CHECK-NEXT: [[ASHR:%.*]] = ashr <2 x i32> [[V:%.*]], -; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i32> [[ASHR]] to <2 x i64> -; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i64> [[SEXT]], +; CHECK-NEXT: [[MULCONV:%.*]] = mul nsw <2 x i32> [[ASHR]], +; CHECK-NEXT: [[MUL:%.*]] = sext <2 x i32> [[MULCONV]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[MUL]] ; %ashr = ashr <2 x i32> %V, @@ -279,8 +279,8 @@ define <2 x i64> @test9_vec(<2 x i32> %V) { ; CHECK-LABEL: @test9_vec( ; CHECK-NEXT: [[ASHR:%.*]] = ashr <2 x i32> [[V:%.*]], -; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i32> [[ASHR]] to <2 x i64> -; CHECK-NEXT: [[MUL:%.*]] = mul nsw <2 x i64> [[SEXT]], +; CHECK-NEXT: [[MULCONV:%.*]] = mul nsw <2 x i32> [[ASHR]], +; CHECK-NEXT: [[MUL:%.*]] = sext <2 x i32> [[MULCONV]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[MUL]] ; %ashr = ashr <2 x i32> %V, @@ -305,8 +305,8 @@ define <2 x i64> @test10_splat(<2 x i32> %V) { ; CHECK-LABEL: @test10_splat( ; CHECK-NEXT: [[LSHR:%.*]] = lshr <2 x i32> [[V:%.*]], -; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i32> [[LSHR]] to <2 x i64> -; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw <2 x i64> [[ZEXT]], +; CHECK-NEXT: [[MULCONV:%.*]] = mul nuw <2 x i32> [[LSHR]], +; CHECK-NEXT: [[MUL:%.*]] = zext <2 x i32> [[MULCONV]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[MUL]] ; %lshr = lshr <2 x i32> %V, @@ -318,8 +318,8 @@ define <2 x i64> @test10_vec(<2 x i32> %V) { ; CHECK-LABEL: @test10_vec( ; CHECK-NEXT: [[LSHR:%.*]] = lshr <2 x i32> [[V:%.*]], -; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i32> [[LSHR]] to <2 x i64> -; CHECK-NEXT: [[MUL:%.*]] = mul nuw nsw <2 x i64> [[ZEXT]], +; CHECK-NEXT: [[MULCONV:%.*]] = mul nuw <2 x i32> [[LSHR]], +; CHECK-NEXT: [[MUL:%.*]] = zext <2 x i32> [[MULCONV]] to <2 x i64> ; CHECK-NEXT: ret <2 x i64> [[MUL]] ; %lshr = lshr <2 x i32> %V,