2002-04-30 00:24:24 +02:00
|
|
|
; This test makes sure that mul instructions are properly eliminated.
|
2009-09-09 00:34:10 +02:00
|
|
|
; RUN: opt < %s -instcombine -S | not grep mul
|
2002-04-30 00:24:24 +02:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test1(i32 %A) {
|
|
|
|
%B = mul i32 %A, 1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2003-03-10 20:44:01 +01:00
|
|
|
}
|
2002-04-30 00:24:24 +02:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test2(i32 %A) {
|
|
|
|
; Should convert to an add instruction
|
|
|
|
%B = mul i32 %A, 2 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2003-03-10 20:44:01 +01:00
|
|
|
}
|
2002-04-30 00:24:24 +02:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test3(i32 %A) {
|
|
|
|
; This should disappear entirely
|
|
|
|
%B = mul i32 %A, 0 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2003-03-10 20:44:01 +01:00
|
|
|
}
|
2002-04-30 00:24:24 +02:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define double @test4(double %A) {
|
|
|
|
; This is safe for FP
|
2009-06-05 00:49:04 +02:00
|
|
|
%B = fmul double 1.000000e+00, %A ; <double> [#uses=1]
|
2008-03-18 04:45:45 +01:00
|
|
|
ret double %B
|
2003-02-18 20:28:47 +01:00
|
|
|
}
|
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test5(i32 %A) {
|
|
|
|
%B = mul i32 %A, 8 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2003-02-18 20:28:47 +01:00
|
|
|
}
|
2003-03-10 23:43:56 +01:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i8 @test6(i8 %A) {
|
|
|
|
%B = mul i8 %A, 8 ; <i8> [#uses=1]
|
|
|
|
%C = mul i8 %B, 8 ; <i8> [#uses=1]
|
|
|
|
ret i8 %C
|
2003-03-10 23:43:56 +01:00
|
|
|
}
|
2003-06-25 19:10:34 +02:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test7(i32 %i) {
|
|
|
|
%tmp = mul i32 %i, -1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %tmp
|
2003-06-25 19:10:34 +02:00
|
|
|
}
|
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i64 @test8(i64 %i) {
|
|
|
|
; tmp = sub 0, %i
|
|
|
|
%j = mul i64 %i, -1 ; <i64> [#uses=1]
|
|
|
|
ret i64 %j
|
2003-06-25 19:10:34 +02:00
|
|
|
}
|
2003-09-12 00:23:48 +02:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test9(i32 %i) {
|
|
|
|
; %j = sub 0, %i
|
|
|
|
%j = mul i32 %i, -1 ; <i32> [#uses=1]
|
|
|
|
ret i32 %j
|
2003-09-12 00:23:48 +02:00
|
|
|
}
|
2004-02-23 06:38:47 +01:00
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test10(i32 %a, i32 %b) {
|
|
|
|
%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
|
2004-02-23 06:38:47 +01:00
|
|
|
}
|
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test11(i32 %a, i32 %b) {
|
|
|
|
%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
|
2004-02-23 06:59:52 +01:00
|
|
|
}
|
|
|
|
|
2008-03-18 04:45:45 +01:00
|
|
|
define i32 @test12(i8 %a, i32 %b) {
|
|
|
|
%c = icmp ugt i8 %a, 127 ; <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
|
2004-02-23 07:37:33 +01:00
|
|
|
}
|
|
|
|
|
2008-08-12 00:06:05 +02:00
|
|
|
; PR2642
|
|
|
|
define internal void @test13(<4 x float>*) {
|
|
|
|
load <4 x float>* %0, align 1
|
2009-06-05 00:49:04 +02:00
|
|
|
fmul <4 x float> %2, < float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00 >
|
2008-08-12 00:06:05 +02:00
|
|
|
store <4 x float> %3, <4 x float>* %0, align 1
|
|
|
|
ret void
|
|
|
|
}
|
2009-07-14 04:01:53 +02:00
|
|
|
|
|
|
|
define <16 x i8> @test14(<16 x i8> %a) {
|
|
|
|
%b = mul <16 x i8> %a, zeroinitializer
|
|
|
|
ret <16 x i8> %b
|
|
|
|
}
|
2009-10-11 09:53:15 +02:00
|
|
|
|
|
|
|
; rdar://7293527
|
|
|
|
define i32 @test15(i32 %A, i32 %B) {
|
|
|
|
entry:
|
|
|
|
%shl = shl i32 1, %B
|
|
|
|
%m = mul i32 %shl, %A
|
|
|
|
ret i32 %m
|
|
|
|
}
|
2009-10-11 23:22:21 +02:00
|
|
|
|
|
|
|
; X * Y (when Y is 0 or 1) --> x & (0-Y)
|
|
|
|
define i32 @test16(i32 %b, i1 %c) {
|
|
|
|
%d = zext i1 %c to i32 ; <i32> [#uses=1]
|
|
|
|
; e = b & (a >> 31)
|
|
|
|
%e = mul i32 %d, %b ; <i32> [#uses=1]
|
|
|
|
ret i32 %e
|
|
|
|
}
|
|
|
|
|
2009-10-11 23:29:45 +02:00
|
|
|
; X * Y (when Y is 0 or 1) --> x & (0-Y)
|
|
|
|
define i32 @test17(i32 %a, i32 %b) {
|
|
|
|
%a.lobit = lshr i32 %a, 31
|
|
|
|
%e = mul i32 %a.lobit, %b
|
|
|
|
ret i32 %e
|
|
|
|
}
|
|
|
|
|
2009-10-11 23:22:21 +02:00
|
|
|
|
|
|
|
|