diff options
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 17 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/trunc-binop-ext.ll | 20 |
2 files changed, 15 insertions, 22 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index c2fe661c467..178c8eaf250 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -552,8 +552,15 @@ Instruction *InstCombiner::narrowBinOp(TruncInst &Trunc) { case Instruction::Or: case Instruction::Xor: case Instruction::Add: + case Instruction::Sub: case Instruction::Mul: { Constant *C; + if (match(BinOp0, m_Constant(C))) { + // trunc (binop C, X) --> binop (trunc C', X) + Constant *NarrowC = ConstantExpr::getTrunc(C, DestTy); + Value *TruncX = Builder.CreateTrunc(BinOp1, DestTy); + return BinaryOperator::Create(BinOp->getOpcode(), NarrowC, TruncX); + } if (match(BinOp1, m_Constant(C))) { // trunc (binop X, C) --> binop (trunc X, C') Constant *NarrowC = ConstantExpr::getTrunc(C, DestTy); @@ -573,16 +580,6 @@ Instruction *InstCombiner::narrowBinOp(TruncInst &Trunc) { } break; } - case Instruction::Sub: { - Constant *C; - if (match(BinOp0, m_Constant(C))) { - // trunc (binop C, X) --> binop (trunc C', X) - Constant *NarrowC = ConstantExpr::getTrunc(C, DestTy); - Value *TruncX = Builder.CreateTrunc(BinOp1, DestTy); - return BinaryOperator::Create(BinOp->getOpcode(), NarrowC, TruncX); - } - break; - } default: break; } diff --git a/llvm/test/Transforms/InstCombine/trunc-binop-ext.ll b/llvm/test/Transforms/InstCombine/trunc-binop-ext.ll index c77be5f54e6..40d58f31458 100644 --- a/llvm/test/Transforms/InstCombine/trunc-binop-ext.ll +++ b/llvm/test/Transforms/InstCombine/trunc-binop-ext.ll @@ -98,9 +98,8 @@ define i16 @narrow_zext_add(i16 %x16, i32 %y32) { define i16 @narrow_sext_sub(i16 %x16, i32 %y32) { ; CHECK-LABEL: @narrow_sext_sub( -; CHECK-NEXT: [[X321:%.*]] = zext i16 %x16 to i32 -; CHECK-NEXT: [[B:%.*]] = sub i32 [[X321]], %y32 -; CHECK-NEXT: [[R:%.*]] = trunc i32 [[B]] to i16 +; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 %y32 to i16 +; CHECK-NEXT: [[R:%.*]] = sub i16 %x16, [[TMP1]] ; CHECK-NEXT: ret i16 [[R]] ; %x32 = sext i16 %x16 to i32 @@ -111,9 +110,8 @@ define i16 @narrow_sext_sub(i16 %x16, i32 %y32) { define i16 @narrow_zext_sub(i16 %x16, i32 %y32) { ; CHECK-LABEL: @narrow_zext_sub( -; CHECK-NEXT: [[X32:%.*]] = zext i16 %x16 to i32 -; CHECK-NEXT: [[B:%.*]] = sub i32 [[X32]], %y32 -; CHECK-NEXT: [[R:%.*]] = trunc i32 [[B]] to i16 +; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 %y32 to i16 +; CHECK-NEXT: [[R:%.*]] = sub i16 %x16, [[TMP1]] ; CHECK-NEXT: ret i16 [[R]] ; %x32 = zext i16 %x16 to i32 @@ -264,9 +262,8 @@ define <2 x i16> @narrow_zext_add_commute(<2 x i16> %x16, <2 x i32> %y32) { define <2 x i16> @narrow_sext_sub_commute(<2 x i16> %x16, <2 x i32> %y32) { ; CHECK-LABEL: @narrow_sext_sub_commute( ; CHECK-NEXT: [[Y32OP0:%.*]] = sdiv <2 x i32> %y32, <i32 7, i32 -17> -; CHECK-NEXT: [[X321:%.*]] = zext <2 x i16> %x16 to <2 x i32> -; CHECK-NEXT: [[B:%.*]] = sub <2 x i32> [[Y32OP0]], [[X321]] -; CHECK-NEXT: [[R:%.*]] = trunc <2 x i32> [[B]] to <2 x i16> +; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i32> [[Y32OP0]] to <2 x i16> +; CHECK-NEXT: [[R:%.*]] = sub <2 x i16> [[TMP1]], %x16 ; CHECK-NEXT: ret <2 x i16> [[R]] ; %y32op0 = sdiv <2 x i32> %y32, <i32 7, i32 -17> @@ -279,9 +276,8 @@ define <2 x i16> @narrow_sext_sub_commute(<2 x i16> %x16, <2 x i32> %y32) { define <2 x i16> @narrow_zext_sub_commute(<2 x i16> %x16, <2 x i32> %y32) { ; CHECK-LABEL: @narrow_zext_sub_commute( ; CHECK-NEXT: [[Y32OP0:%.*]] = sdiv <2 x i32> %y32, <i32 7, i32 -17> -; CHECK-NEXT: [[X32:%.*]] = zext <2 x i16> %x16 to <2 x i32> -; CHECK-NEXT: [[B:%.*]] = sub <2 x i32> [[Y32OP0]], [[X32]] -; CHECK-NEXT: [[R:%.*]] = trunc <2 x i32> [[B]] to <2 x i16> +; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i32> [[Y32OP0]] to <2 x i16> +; CHECK-NEXT: [[R:%.*]] = sub <2 x i16> [[TMP1]], %x16 ; CHECK-NEXT: ret <2 x i16> [[R]] ; %y32op0 = sdiv <2 x i32> %y32, <i32 7, i32 -17> |