2002-04-29 22:24:24 +00:00
|
|
|
; This test makes sure that mul instructions are properly eliminated.
|
2012-03-18 23:28:48 +00:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2002-04-29 22:24:24 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test1(i32 %A) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test1(
|
2008-03-18 03:45:45 +00:00
|
|
|
%B = mul i32 %A, 1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: ret i32 %A
|
2003-03-10 19:44:01 +00:00
|
|
|
}
|
2002-04-29 22:24:24 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test2(i32 %A) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test2(
|
2008-03-18 03:45:45 +00:00
|
|
|
; Should convert to an add instruction
|
|
|
|
%B = mul i32 %A, 2 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: shl i32 %A, 1
|
2003-03-10 19:44:01 +00:00
|
|
|
}
|
2002-04-29 22:24:24 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test3(i32 %A) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test3(
|
2008-03-18 03:45:45 +00:00
|
|
|
; This should disappear entirely
|
|
|
|
%B = mul i32 %A, 0 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: ret i32 0
|
2003-03-10 19:44:01 +00:00
|
|
|
}
|
2002-04-29 22:24:24 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define double @test4(double %A) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test4(
|
2008-03-18 03:45:45 +00:00
|
|
|
; This is safe for FP
|
2009-06-04 22:49:04 +00:00
|
|
|
%B = fmul double 1.000000e+00, %A ; <double> [#uses=1]
|
2008-03-18 03:45:45 +00:00
|
|
|
ret double %B
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: ret double %A
|
2003-02-18 19:28:47 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test5(i32 %A) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test5(
|
2008-03-18 03:45:45 +00:00
|
|
|
%B = mul i32 %A, 8 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: shl i32 %A, 3
|
2003-02-18 19:28:47 +00:00
|
|
|
}
|
2003-03-10 22:43:56 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i8 @test6(i8 %A) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test6(
|
2008-03-18 03:45:45 +00:00
|
|
|
%B = mul i8 %A, 8 ; <i8> [#uses=1]
|
|
|
|
%C = mul i8 %B, 8 ; <i8> [#uses=1]
|
|
|
|
ret i8 %C
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: shl i8 %A, 6
|
2003-03-10 22:43:56 +00:00
|
|
|
}
|
2003-06-25 17:10:34 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test7(i32 %i) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test7(
|
2008-03-18 03:45:45 +00:00
|
|
|
%tmp = mul i32 %i, -1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %tmp
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: sub i32 0, %i
|
2003-06-25 17:10:34 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i64 @test8(i64 %i) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test8(
|
2008-03-18 03:45:45 +00:00
|
|
|
%j = mul i64 %i, -1 ; <i64> [#uses=1]
|
|
|
|
ret i64 %j
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: sub i64 0, %i
|
2003-06-25 17:10:34 +00:00
|
|
|
}
|
2003-09-11 22:23:48 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test9(i32 %i) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test9(
|
2008-03-18 03:45:45 +00:00
|
|
|
%j = mul i32 %i, -1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %j
|
2012-12-06 21:24:47 +00:00
|
|
|
; CHECK: sub i32 0, %i
|
2003-09-11 22:23:48 +00:00
|
|
|
}
|
2004-02-23 05:38:47 +00:00
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test10(i32 %a, i32 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test10(
|
2008-03-18 03:45:45 +00:00
|
|
|
%c = icmp slt i32 %a, 0 ; <i1> [#uses=1]
|
|
|
|
%d = zext i1 %c to i32 ; <i32> [#uses=1]
|
|
|
|
; e = b & (a >> 31)
|
|
|
|
%e = mul i32 %d, %b ; <i32> [#uses=1]
|
|
|
|
ret i32 %e
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: [[TEST10:%.*]] = ashr i32 %a, 31
|
|
|
|
; CHECK-NEXT: %e = and i32 [[TEST10]], %b
|
|
|
|
; CHECK-NEXT: ret i32 %e
|
2004-02-23 05:38:47 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 03:45:45 +00:00
|
|
|
define i32 @test11(i32 %a, i32 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test11(
|
2008-03-18 03:45:45 +00:00
|
|
|
%c = icmp sle i32 %a, -1 ; <i1> [#uses=1]
|
|
|
|
%d = zext i1 %c to i32 ; <i32> [#uses=1]
|
|
|
|
; e = b & (a >> 31)
|
|
|
|
%e = mul i32 %d, %b ; <i32> [#uses=1]
|
|
|
|
ret i32 %e
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: [[TEST11:%.*]] = ashr i32 %a, 31
|
|
|
|
; CHECK-NEXT: %e = and i32 [[TEST11]], %b
|
|
|
|
; CHECK-NEXT: ret i32 %e
|
2004-02-23 05:59:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-18 23:28:48 +00:00
|
|
|
define i32 @test12(i32 %a, i32 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test12(
|
2012-03-18 23:28:48 +00:00
|
|
|
%c = icmp ugt i32 %a, 2147483647 ; <i1> [#uses=1]
|
2008-03-18 03:45:45 +00:00
|
|
|
%d = zext i1 %c to i32 ; <i32> [#uses=1]
|
|
|
|
%e = mul i32 %d, %b ; <i32> [#uses=1]
|
|
|
|
ret i32 %e
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: [[TEST12:%.*]] = ashr i32 %a, 31
|
|
|
|
; CHECK-NEXT: %e = and i32 [[TEST12]], %b
|
|
|
|
; CHECK-NEXT: ret i32 %e
|
|
|
|
|
2004-02-23 06:37:33 +00:00
|
|
|
}
|
|
|
|
|
2008-08-11 22:06:05 +00:00
|
|
|
; PR2642
|
|
|
|
define internal void @test13(<4 x float>*) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test13(
|
2008-08-11 22:06:05 +00:00
|
|
|
load <4 x float>* %0, align 1
|
2009-06-04 22:49:04 +00:00
|
|
|
fmul <4 x float> %2, < float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00 >
|
2008-08-11 22:06:05 +00:00
|
|
|
store <4 x float> %3, <4 x float>* %0, align 1
|
|
|
|
ret void
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK-NEXT: ret void
|
2008-08-11 22:06:05 +00:00
|
|
|
}
|
2009-07-14 02:01:53 +00:00
|
|
|
|
|
|
|
define <16 x i8> @test14(<16 x i8> %a) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test14(
|
2009-07-14 02:01:53 +00:00
|
|
|
%b = mul <16 x i8> %a, zeroinitializer
|
|
|
|
ret <16 x i8> %b
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK-NEXT: ret <16 x i8> zeroinitializer
|
2009-07-14 02:01:53 +00:00
|
|
|
}
|
2009-10-11 07:53:15 +00:00
|
|
|
|
|
|
|
; rdar://7293527
|
|
|
|
define i32 @test15(i32 %A, i32 %B) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test15(
|
2009-10-11 07:53:15 +00:00
|
|
|
entry:
|
|
|
|
%shl = shl i32 1, %B
|
|
|
|
%m = mul i32 %shl, %A
|
|
|
|
ret i32 %m
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: shl i32 %A, %B
|
2009-10-11 07:53:15 +00:00
|
|
|
}
|
2009-10-11 21:22:21 +00:00
|
|
|
|
|
|
|
; X * Y (when Y is 0 or 1) --> x & (0-Y)
|
|
|
|
define i32 @test16(i32 %b, i1 %c) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test16(
|
2009-10-11 21:22:21 +00:00
|
|
|
%d = zext i1 %c to i32 ; <i32> [#uses=1]
|
|
|
|
; e = b & (a >> 31)
|
|
|
|
%e = mul i32 %d, %b ; <i32> [#uses=1]
|
|
|
|
ret i32 %e
|
2013-01-30 06:35:22 +00:00
|
|
|
; CHECK: [[TEST16:%.*]] = select i1 %c, i32 %b, i32 0
|
|
|
|
; CHECK-NEXT: ret i32 [[TEST16]]
|
2009-10-11 21:22:21 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 21:29:45 +00:00
|
|
|
; X * Y (when Y is 0 or 1) --> x & (0-Y)
|
|
|
|
define i32 @test17(i32 %a, i32 %b) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test17(
|
2009-10-11 21:29:45 +00:00
|
|
|
%a.lobit = lshr i32 %a, 31
|
|
|
|
%e = mul i32 %a.lobit, %b
|
|
|
|
ret i32 %e
|
2012-03-18 23:28:48 +00:00
|
|
|
; CHECK: [[TEST17:%.*]] = ashr i32 %a, 31
|
|
|
|
; CHECK-NEXT: %e = and i32 [[TEST17]], %b
|
|
|
|
; CHECK-NEXT: ret i32 %e
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test18(i32 %A, i32 %B) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test18(
|
2012-03-18 23:28:48 +00:00
|
|
|
%C = and i32 %A, 1
|
|
|
|
%D = and i32 %B, 1
|
|
|
|
|
|
|
|
%E = mul i32 %C, %D
|
|
|
|
%F = and i32 %E, 16
|
|
|
|
ret i32 %F
|
|
|
|
; CHECK-NEXT: ret i32 0
|
2009-10-11 21:29:45 +00:00
|
|
|
}
|
|
|
|
|
2012-03-18 23:28:48 +00:00
|
|
|
declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32)
|
|
|
|
declare void @use(i1)
|
2009-10-11 21:22:21 +00:00
|
|
|
|
2012-03-18 23:28:48 +00:00
|
|
|
define i32 @test19(i32 %A, i32 %B) {
|
2013-07-14 01:42:54 +00:00
|
|
|
; CHECK-LABEL: @test19(
|
2012-03-18 23:28:48 +00:00
|
|
|
%C = and i32 %A, 1
|
|
|
|
%D = and i32 %B, 1
|
2009-10-11 21:22:21 +00:00
|
|
|
|
2012-03-18 23:28:48 +00:00
|
|
|
; It would be nice if we also started proving that this doesn't overflow.
|
|
|
|
%E = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %C, i32 %D)
|
|
|
|
%F = extractvalue {i32, i1} %E, 0
|
|
|
|
%G = extractvalue {i32, i1} %E, 1
|
|
|
|
call void @use(i1 %G)
|
|
|
|
%H = and i32 %F, 16
|
|
|
|
ret i32 %H
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
2014-01-19 15:24:22 +00:00
|
|
|
|
|
|
|
define <2 x i64> @test20(<2 x i64> %A) {
|
|
|
|
; CHECK-LABEL: @test20(
|
|
|
|
%B = add <2 x i64> %A, <i64 12, i64 14>
|
|
|
|
%C = mul <2 x i64> %B, <i64 3, i64 2>
|
|
|
|
ret <2 x i64> %C
|
|
|
|
; CHECK: mul <2 x i64> %A, <i64 3, i64 2>
|
|
|
|
; CHECK: add <2 x i64> %{{.}}, <i64 36, i64 28>
|
|
|
|
}
|
|
|
|
|
|
|
|
define <2 x i1> @test21(<2 x i1> %A, <2 x i1> %B) {
|
|
|
|
; CHECK-LABEL: @test21(
|
|
|
|
%C = mul <2 x i1> %A, %B
|
|
|
|
ret <2 x i1> %C
|
|
|
|
; CHECK: %C = and <2 x i1> %A, %B
|
|
|
|
}
|
2014-11-22 04:52:38 +00:00
|
|
|
|
|
|
|
define i32 @test22(i32 %A) {
|
|
|
|
; CHECK-LABEL: @test22(
|
|
|
|
%B = mul nsw i32 %A, -1
|
|
|
|
ret i32 %B
|
|
|
|
; CHECK: sub nsw i32 0, %A
|
|
|
|
}
|
2014-11-22 04:52:52 +00:00
|
|
|
|
|
|
|
define i32 @test23(i32 %A) {
|
|
|
|
; CHECK-LABEL: @test23(
|
|
|
|
%B = shl nuw i32 %A, 1
|
|
|
|
%C = mul nuw i32 %B, 3
|
|
|
|
ret i32 %C
|
|
|
|
; CHECK: mul nuw i32 %A, 6
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test24(i32 %A) {
|
|
|
|
; CHECK-LABEL: @test24(
|
|
|
|
%B = shl nsw i32 %A, 1
|
|
|
|
%C = mul nsw i32 %B, 3
|
|
|
|
ret i32 %C
|
|
|
|
; CHECK: mul nsw i32 %A, 6
|
|
|
|
}
|
2014-11-22 07:25:19 +00:00
|
|
|
|
|
|
|
define i32 @test25(i32 %A, i32 %B) {
|
|
|
|
; CHECK-LABEL: @test25(
|
|
|
|
%C = sub nsw i32 0, %A
|
|
|
|
%D = sub nsw i32 0, %B
|
|
|
|
%E = mul nsw i32 %C, %D
|
|
|
|
ret i32 %E
|
|
|
|
; CHECK: mul nsw i32 %A, %B
|
|
|
|
}
|
2014-11-22 08:57:02 +00:00
|
|
|
|
|
|
|
define i32 @test26(i32 %A, i32 %B) {
|
|
|
|
; CHECK-LABEL: @test26(
|
|
|
|
%C = shl nsw i32 1, %B
|
|
|
|
%D = mul nsw i32 %A, %C
|
|
|
|
ret i32 %D
|
|
|
|
; CHECK: shl nsw i32 %A, %B
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test27(i32 %A, i32 %B) {
|
|
|
|
; CHECK-LABEL: @test27(
|
|
|
|
%C = shl i32 1, %B
|
|
|
|
%D = mul nuw i32 %A, %C
|
|
|
|
ret i32 %D
|
|
|
|
; CHECK: shl nuw i32 %A, %B
|
|
|
|
}
|
2014-11-24 16:41:13 +00:00
|
|
|
|
|
|
|
define i32 @test28(i32 %A) {
|
|
|
|
; CHECK-LABEL: @test28(
|
|
|
|
%B = shl i32 1, %A
|
|
|
|
%C = mul nsw i32 %B, %B
|
|
|
|
ret i32 %C
|
|
|
|
; CHECK: %[[shl1:.*]] = shl i32 1, %A
|
|
|
|
; CHECK-NEXT: %[[shl2:.*]] = shl i32 %[[shl1]], %A
|
|
|
|
; CHECK-NEXT: ret i32 %[[shl2]]
|
|
|
|
}
|
2014-12-26 09:10:14 +00:00
|
|
|
|
|
|
|
define i64 @test29(i31 %A, i31 %B) {
|
|
|
|
; CHECK-LABEL: @test29(
|
|
|
|
%C = zext i31 %A to i64
|
|
|
|
%D = zext i31 %B to i64
|
|
|
|
%E = mul i64 %C, %D
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: %[[zext1:.*]] = zext i31 %A to i64
|
|
|
|
; CHECK-NEXT: %[[zext2:.*]] = zext i31 %B to i64
|
|
|
|
; CHECK-NEXT: %[[mul:.*]] = mul nsw i64 %[[zext1]], %[[zext2]]
|
|
|
|
; CHECK-NEXT: ret i64 %[[mul]]
|
|
|
|
}
|