[llvm] r325037 - [InstCombine, InstSimplify] (re)move tests, regenerate checks; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 10:22:53 PST 2018
Author: spatel
Date: Tue Feb 13 10:22:53 2018
New Revision: 325037
URL: http://llvm.org/viewvc/llvm-project?rev=325037&view=rev
Log:
[InstCombine, InstSimplify] (re)move tests, regenerate checks; NFC
The InstCombine integer mul test file had tests that belong in InstSimplify
(including fmul tests). Move things to where they belong and auto-generate
complete checks for everything.
Modified:
llvm/trunk/test/Transforms/InstCombine/mul.ll
llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
llvm/trunk/test/Transforms/InstSimplify/mul.ll
Modified: llvm/trunk/test/Transforms/InstCombine/mul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/mul.ll?rev=325037&r1=325036&r2=325037&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/mul.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/mul.ll Tue Feb 13 10:22:53 2018
@@ -1,168 +1,125 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; This test makes sure that mul instructions are properly eliminated.
; RUN: opt < %s -instcombine -S | FileCheck %s
-define i32 @test1(i32 %A) {
-; CHECK-LABEL: @test1(
- %B = mul i32 %A, 1 ; <i32> [#uses=1]
- ret i32 %B
-; CHECK: ret i32 %A
-}
-
-define i32 @test2(i32 %A) {
-; CHECK-LABEL: @test2(
- ; Should convert to an add instruction
- %B = mul i32 %A, 2 ; <i32> [#uses=1]
- ret i32 %B
-; CHECK: shl i32 %A, 1
-}
-
-define i32 @test3(i32 %A) {
-; CHECK-LABEL: @test3(
- ; This should disappear entirely
- %B = mul i32 %A, 0 ; <i32> [#uses=1]
- ret i32 %B
-; CHECK: ret i32 0
-}
-
-define double @test4(double %A) {
-; CHECK-LABEL: @test4(
- ; This is safe for FP
- %B = fmul double 1.000000e+00, %A ; <double> [#uses=1]
- ret double %B
-; CHECK: ret double %A
-}
-
-define i32 @test5(i32 %A) {
-; CHECK-LABEL: @test5(
- %B = mul i32 %A, 8 ; <i32> [#uses=1]
- ret i32 %B
-; CHECK: shl i32 %A, 3
-}
-
-define i8 @test6(i8 %A) {
-; CHECK-LABEL: @test6(
- %B = mul i8 %A, 8 ; <i8> [#uses=1]
- %C = mul i8 %B, 8 ; <i8> [#uses=1]
- ret i8 %C
-; CHECK: shl i8 %A, 6
-}
-
-define i32 @test7(i32 %i) {
-; CHECK-LABEL: @test7(
- %tmp = mul i32 %i, -1 ; <i32> [#uses=1]
- ret i32 %tmp
-; CHECK: sub i32 0, %i
-}
-
-define i64 @test8(i64 %i) {
-; CHECK-LABEL: @test8(
- %j = mul i64 %i, -1 ; <i64> [#uses=1]
- ret i64 %j
-; CHECK: sub i64 0, %i
-}
-
-define i32 @test9(i32 %i) {
-; CHECK-LABEL: @test9(
- %j = mul i32 %i, -1 ; <i32> [#uses=1]
- ret i32 %j
-; CHECK: sub i32 0, %i
+define i32 @pow2_multiplier(i32 %A) {
+; CHECK-LABEL: @pow2_multiplier(
+; CHECK-NEXT: [[B:%.*]] = shl i32 [[A:%.*]], 1
+; CHECK-NEXT: ret i32 [[B]]
+;
+ %B = mul i32 %A, 2
+ ret i32 %B
+}
+
+define <2 x i32> @pow2_multiplier_vec(<2 x i32> %A) {
+; CHECK-LABEL: @pow2_multiplier_vec(
+; CHECK-NEXT: [[B:%.*]] = shl <2 x i32> [[A:%.*]], <i32 3, i32 3>
+; CHECK-NEXT: ret <2 x i32> [[B]]
+;
+ %B = mul <2 x i32> %A, <i32 8, i32 8>
+ ret <2 x i32> %B
+}
+
+define i8 @combine_shl(i8 %A) {
+; CHECK-LABEL: @combine_shl(
+; CHECK-NEXT: [[C:%.*]] = shl i8 [[A:%.*]], 6
+; CHECK-NEXT: ret i8 [[C]]
+;
+ %B = mul i8 %A, 8
+ %C = mul i8 %B, 8
+ ret i8 %C
+}
+
+define i32 @neg(i32 %i) {
+; CHECK-LABEL: @neg(
+; CHECK-NEXT: [[TMP:%.*]] = sub i32 0, [[I:%.*]]
+; CHECK-NEXT: ret i32 [[TMP]]
+;
+ %tmp = mul i32 %i, -1
+ ret i32 %tmp
}
define i32 @test10(i32 %a, i32 %b) {
; CHECK-LABEL: @test10(
- %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
-; CHECK: [[TEST10:%.*]] = ashr i32 %a, 31
-; CHECK-NEXT: %e = and i32 [[TEST10]], %b
-; CHECK-NEXT: ret i32 %e
+; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
+; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[E]]
+;
+ %c = icmp slt i32 %a, 0
+ %d = zext i1 %c to i32
+ ; e = b & (a >> 31)
+ %e = mul i32 %d, %b
+ ret i32 %e
}
define i32 @test11(i32 %a, i32 %b) {
; CHECK-LABEL: @test11(
- %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
-; CHECK: [[TEST11:%.*]] = ashr i32 %a, 31
-; CHECK-NEXT: %e = and i32 [[TEST11]], %b
-; CHECK-NEXT: ret i32 %e
+; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
+; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[E]]
+;
+ %c = icmp sle i32 %a, -1
+ %d = zext i1 %c to i32
+ ; e = b & (a >> 31)
+ %e = mul i32 %d, %b
+ ret i32 %e
}
define i32 @test12(i32 %a, i32 %b) {
; CHECK-LABEL: @test12(
- %c = icmp ugt i32 %a, 2147483647 ; <i1> [#uses=1]
- %d = zext i1 %c to i32 ; <i32> [#uses=1]
- %e = mul i32 %d, %b ; <i32> [#uses=1]
- ret i32 %e
-; CHECK: [[TEST12:%.*]] = ashr i32 %a, 31
-; CHECK-NEXT: %e = and i32 [[TEST12]], %b
-; CHECK-NEXT: ret i32 %e
-
-}
-
-; PR2642
-define internal void @test13(<4 x float>*) {
-; CHECK-LABEL: @test13(
- load <4 x float>, <4 x float>* %0, align 1
- fmul <4 x float> %2, < float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00 >
- store <4 x float> %3, <4 x float>* %0, align 1
- ret void
-; CHECK-NEXT: ret void
-}
-
-define <16 x i8> @test14(<16 x i8> %a) {
-; CHECK-LABEL: @test14(
- %b = mul <16 x i8> %a, zeroinitializer
- ret <16 x i8> %b
-; CHECK-NEXT: ret <16 x i8> zeroinitializer
+; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
+; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[E]]
+;
+ %c = icmp ugt i32 %a, 2147483647
+ %d = zext i1 %c to i32
+ %e = mul i32 %d, %b
+ ret i32 %e
}
; rdar://7293527
define i32 @test15(i32 %A, i32 %B) {
; CHECK-LABEL: @test15(
-entry:
+; CHECK-NEXT: [[M:%.*]] = shl i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[M]]
+;
%shl = shl i32 1, %B
%m = mul i32 %shl, %A
ret i32 %m
-; CHECK: shl i32 %A, %B
}
; X * Y (when Y is 0 or 1) --> x & (0-Y)
define i32 @test16(i32 %b, i1 %c) {
; CHECK-LABEL: @test16(
- %d = zext i1 %c to i32 ; <i32> [#uses=1]
- ; e = b & (a >> 31)
- %e = mul i32 %d, %b ; <i32> [#uses=1]
- ret i32 %e
-; CHECK: [[TEST16:%.*]] = select i1 %c, i32 %b, i32 0
-; CHECK-NEXT: ret i32 [[TEST16]]
+; CHECK-NEXT: [[E:%.*]] = select i1 [[C:%.*]], i32 [[B:%.*]], i32 0
+; CHECK-NEXT: ret i32 [[E]]
+;
+ %d = zext i1 %c to i32
+ ; e = b & (a >> 31)
+ %e = mul i32 %d, %b
+ ret i32 %e
}
; X * Y (when Y is 0 or 1) --> x & (0-Y)
define i32 @test17(i32 %a, i32 %b) {
; CHECK-LABEL: @test17(
+; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[A:%.*]], 31
+; CHECK-NEXT: [[E:%.*]] = and i32 [[TMP1]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[E]]
+;
%a.lobit = lshr i32 %a, 31
%e = mul i32 %a.lobit, %b
ret i32 %e
-; 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) {
; CHECK-LABEL: @test18(
+; CHECK-NEXT: ret i32 0
+;
%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
}
declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32)
@@ -170,6 +127,9 @@ declare void @use(i1)
define i32 @test19(i32 %A, i32 %B) {
; CHECK-LABEL: @test19(
+; CHECK-NEXT: call void @use(i1 false)
+; CHECK-NEXT: ret i32 0
+;
%C = and i32 %A, 1
%D = and i32 %B, 1
@@ -180,122 +140,142 @@ define i32 @test19(i32 %A, i32 %B) {
call void @use(i1 %G)
%H = and i32 %F, 16
ret i32 %H
-; CHECK: ret i32 0
}
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>
+; CHECK-NEXT: [[TMP1:%.*]] = mul <2 x i64> [[A:%.*]], <i64 3, i64 2>
+; CHECK-NEXT: [[C:%.*]] = add <2 x i64> [[TMP1]], <i64 36, i64 28>
+; CHECK-NEXT: ret <2 x i64> [[C]]
+;
+ %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
}
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
+; CHECK-NEXT: [[C:%.*]] = and <2 x i1> [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret <2 x i1> [[C]]
+;
+ %C = mul <2 x i1> %A, %B
+ ret <2 x i1> %C
}
define i32 @test22(i32 %A) {
; CHECK-LABEL: @test22(
- %B = mul nsw i32 %A, -1
- ret i32 %B
-; CHECK: sub nsw i32 0, %A
+; CHECK-NEXT: [[B:%.*]] = sub nsw i32 0, [[A:%.*]]
+; CHECK-NEXT: ret i32 [[B]]
+;
+ %B = mul nsw i32 %A, -1
+ ret i32 %B
}
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
+; CHECK-NEXT: [[C:%.*]] = mul nuw i32 [[A:%.*]], 6
+; CHECK-NEXT: ret i32 [[C]]
+;
+ %B = shl nuw i32 %A, 1
+ %C = mul nuw i32 %B, 3
+ ret i32 %C
}
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
+; CHECK-NEXT: [[C:%.*]] = mul nsw i32 [[A:%.*]], 6
+; CHECK-NEXT: ret i32 [[C]]
+;
+ %B = shl nsw i32 %A, 1
+ %C = mul nsw i32 %B, 3
+ ret i32 %C
}
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
+; CHECK-NEXT: [[E:%.*]] = mul nsw i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[E]]
+;
+ %C = sub nsw i32 0, %A
+ %D = sub nsw i32 0, %B
+ %E = mul nsw i32 %C, %D
+ ret i32 %E
}
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
+; CHECK-NEXT: [[D:%.*]] = shl nsw i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[D]]
+;
+ %C = shl nsw i32 1, %B
+ %D = mul nsw i32 %A, %C
+ ret i32 %D
}
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
+; CHECK-NEXT: [[D:%.*]] = shl nuw i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: ret i32 [[D]]
+;
+ %C = shl i32 1, %B
+ %D = mul nuw i32 %A, %C
+ ret i32 %D
}
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]]
+; CHECK-NEXT: [[B:%.*]] = shl i32 1, [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = shl i32 [[B]], [[A]]
+; CHECK-NEXT: ret i32 [[C]]
+;
+ %B = shl i32 1, %A
+ %C = mul nsw i32 %B, %B
+ ret i32 %C
}
define i64 @test29(i31 %A, i31 %B) {
; CHECK-LABEL: @test29(
- %C = sext i31 %A to i64
- %D = sext i31 %B to i64
- %E = mul i64 %C, %D
- ret i64 %E
-; CHECK: %[[sext1:.*]] = sext i31 %A to i64
-; CHECK-NEXT: %[[sext2:.*]] = sext i31 %B to i64
-; CHECK-NEXT: %[[mul:.*]] = mul nsw i64 %[[sext1]], %[[sext2]]
-; CHECK-NEXT: ret i64 %[[mul]]
+; CHECK-NEXT: [[C:%.*]] = sext i31 [[A:%.*]] to i64
+; CHECK-NEXT: [[D:%.*]] = sext i31 [[B:%.*]] to i64
+; CHECK-NEXT: [[E:%.*]] = mul nsw i64 [[C]], [[D]]
+; CHECK-NEXT: ret i64 [[E]]
+;
+ %C = sext i31 %A to i64
+ %D = sext i31 %B to i64
+ %E = mul i64 %C, %D
+ ret i64 %E
}
define i64 @test30(i32 %A, i32 %B) {
; CHECK-LABEL: @test30(
- %C = zext i32 %A to i64
- %D = zext i32 %B to i64
- %E = mul i64 %C, %D
- ret i64 %E
-; CHECK: %[[zext1:.*]] = zext i32 %A to i64
-; CHECK-NEXT: %[[zext2:.*]] = zext i32 %B to i64
-; CHECK-NEXT: %[[mul:.*]] = mul nuw i64 %[[zext1]], %[[zext2]]
-; CHECK-NEXT: ret i64 %[[mul]]
+; CHECK-NEXT: [[C:%.*]] = zext i32 [[A:%.*]] to i64
+; CHECK-NEXT: [[D:%.*]] = zext i32 [[B:%.*]] to i64
+; CHECK-NEXT: [[E:%.*]] = mul nuw i64 [[C]], [[D]]
+; CHECK-NEXT: ret i64 [[E]]
+;
+ %C = zext i32 %A to i64
+ %D = zext i32 %B to i64
+ %E = mul i64 %C, %D
+ ret i64 %E
}
@PR22087 = external global i32
define i32 @test31(i32 %V) {
-; CHECK-LABEL: @test31
+; CHECK-LABEL: @test31(
+; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[V:%.*]], zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32)
+; CHECK-NEXT: ret i32 [[MUL]]
+;
%mul = mul i32 %V, shl (i32 1, i32 zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32))
ret i32 %mul
-; CHECK: %[[mul:.*]] = shl i32 %V, zext (i1 icmp ne (i32* inttoptr (i64 1 to i32*), i32* @PR22087) to i32)
-; CHECK-NEXT: ret i32 %[[mul]]
}
define i32 @test32(i32 %X) {
-; CHECK-LABEL: @test32
+; CHECK-LABEL: @test32(
+; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[X:%.*]], 31
+; CHECK-NEXT: ret i32 [[MUL]]
+;
%mul = mul nsw i32 %X, -2147483648
ret i32 %mul
-; CHECK: %[[shl:.*]] = shl i32 %X, 31
-; CHECK-NEXT: ret i32 %[[shl]]
}
define <2 x i32> @test32vec(<2 x i32> %X) {
@@ -308,10 +288,11 @@ define <2 x i32> @test32vec(<2 x i32> %X
}
define i32 @test33(i32 %X) {
-; CHECK-LABEL: @test33
+; CHECK-LABEL: @test33(
+; CHECK-NEXT: [[MUL:%.*]] = shl nsw i32 [[X:%.*]], 30
+; CHECK-NEXT: ret i32 [[MUL]]
+;
%mul = mul nsw i32 %X, 1073741824
-; CHECK: %[[shl:.*]] = shl nsw i32 %X, 30
-; CHECK-NEXT: ret i32 %[[shl]]
ret i32 %mul
}
Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll?rev=325037&r1=325036&r2=325037&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Tue Feb 13 10:22:53 2018
@@ -4,7 +4,7 @@
; fsub -0.0, (fsub -0.0, X) ==> X
define float @fsub_-0_-0_x(float %a) {
; CHECK-LABEL: @fsub_-0_-0_x(
-; CHECK-NEXT: ret float %a
+; CHECK-NEXT: ret float [[A:%.*]]
;
%t1 = fsub float -0.0, %a
%ret = fsub float -0.0, %t1
@@ -14,7 +14,7 @@ define float @fsub_-0_-0_x(float %a) {
; fsub 0.0, (fsub -0.0, X) != X
define float @fsub_0_-0_x(float %a) {
; CHECK-LABEL: @fsub_0_-0_x(
-; CHECK-NEXT: [[T1:%.*]] = fsub float 0.000000e+00, %a
+; CHECK-NEXT: [[T1:%.*]] = fsub float 0.000000e+00, [[A:%.*]]
; CHECK-NEXT: [[RET:%.*]] = fsub float -0.000000e+00, [[T1]]
; CHECK-NEXT: ret float [[RET]]
;
@@ -26,7 +26,7 @@ define float @fsub_0_-0_x(float %a) {
; fsub -0.0, (fsub 0.0, X) != X
define float @fsub_-0_0_x(float %a) {
; CHECK-LABEL: @fsub_-0_0_x(
-; CHECK-NEXT: [[T1:%.*]] = fsub float -0.000000e+00, %a
+; CHECK-NEXT: [[T1:%.*]] = fsub float -0.000000e+00, [[A:%.*]]
; CHECK-NEXT: [[RET:%.*]] = fsub float 0.000000e+00, [[T1]]
; CHECK-NEXT: ret float [[RET]]
;
@@ -38,7 +38,7 @@ define float @fsub_-0_0_x(float %a) {
; fsub X, 0 ==> X
define float @fsub_x_0(float %a) {
; CHECK-LABEL: @fsub_x_0(
-; CHECK-NEXT: ret float %a
+; CHECK-NEXT: ret float [[A:%.*]]
;
%ret = fsub float %a, 0.0
ret float %ret
@@ -47,7 +47,7 @@ define float @fsub_x_0(float %a) {
; fadd X, -0 ==> X
define float @fadd_x_n0(float %a) {
; CHECK-LABEL: @fadd_x_n0(
-; CHECK-NEXT: ret float %a
+; CHECK-NEXT: ret float [[A:%.*]]
;
%ret = fadd float %a, -0.0
ret float %ret
@@ -56,16 +56,25 @@ define float @fadd_x_n0(float %a) {
; fmul X, 1.0 ==> X
define double @fmul_X_1(double %a) {
; CHECK-LABEL: @fmul_X_1(
-; CHECK-NEXT: ret double %a
+; CHECK-NEXT: ret double [[A:%.*]]
;
- %b = fmul double 1.000000e+00, %a
+ %b = fmul double 1.0, %a
ret double %b
}
+; PR2642
+define <4 x float> @fmul_X_1_vec(<4 x float> %x) {
+; CHECK-LABEL: @fmul_X_1_vec(
+; CHECK-NEXT: ret <4 x float> [[X:%.*]]
+;
+ %m = fmul <4 x float> %x, <float 1.0, float 1.0, float 1.0, float 1.0>
+ ret <4 x float> %m
+}
+
; fdiv X, 1.0 ==> X
define float @fdiv_x_1(float %a) {
; CHECK-LABEL: @fdiv_x_1(
-; CHECK-NEXT: ret float %a
+; CHECK-NEXT: ret float [[A:%.*]]
;
%ret = fdiv float %a, 1.0
ret float %ret
@@ -84,7 +93,7 @@ declare float @sqrtf(float)
define float @PR22688(float %x) {
; CHECK-LABEL: @PR22688(
-; CHECK-NEXT: [[TMP1:%.*]] = call float @sqrtf(float %x)
+; CHECK-NEXT: [[TMP1:%.*]] = call float @sqrtf(float [[X:%.*]])
; CHECK-NEXT: [[TMP2:%.*]] = call float @sqrtf(float [[TMP1]])
; CHECK-NEXT: [[TMP3:%.*]] = call float @sqrtf(float [[TMP2]])
; CHECK-NEXT: [[TMP4:%.*]] = call float @sqrtf(float [[TMP3]])
@@ -106,144 +115,176 @@ define float @PR22688(float %x) {
declare float @llvm.fabs.f32(float)
declare float @llvm.sqrt.f32(float)
-; CHECK-LABEL: @fabs_select_positive_constants(
-; CHECK: %select = select i1 %cmp, float 1.000000e+00, float 2.000000e+00
-; CHECK-NEXT: ret float %select
define float @fabs_select_positive_constants(i32 %c) {
+; CHECK-LABEL: @fabs_select_positive_constants(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00
+; CHECK-NEXT: ret float [[SELECT]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 1.0, float 2.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_constant_variable(
-; CHECK: %select = select i1 %cmp, float 1.000000e+00, float %x
-; CHECK-NEXT: %fabs = call float @llvm.fabs.f32(float %select)
define float @fabs_select_constant_variable(i32 %c, float %x) {
+; CHECK-LABEL: @fabs_select_constant_variable(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 1.000000e+00, float [[X:%.*]]
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 1.0, float %x
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_neg0_pos0(
-; CHECK: %select = select i1 %cmp, float -0.000000e+00, float 0.000000e+00
-; CHECK: %fabs = call float @llvm.fabs.f32(float %select)
-; CHECK-NEXT: ret float %fabs
define float @fabs_select_neg0_pos0(float addrspace(1)* %out, i32 %c) {
+; CHECK-LABEL: @fabs_select_neg0_pos0(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float -0.000000e+00, float 0.000000e+00
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float -0.0, float 0.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_neg0_neg1(
-; CHECK: %select = select i1 %cmp, float -0.000000e+00, float -1.000000e+00
-; CHECK: %fabs = call float @llvm.fabs.f32(float %select)
define float @fabs_select_neg0_neg1(float addrspace(1)* %out, i32 %c) {
+; CHECK-LABEL: @fabs_select_neg0_neg1(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float -0.000000e+00, float -1.000000e+00
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float -0.0, float -1.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_nan_nan(
-; CHECK: %select = select i1 %cmp, float 0x7FF8000000000000, float 0x7FF8000100000000
-; CHECK-NEXT: ret float %select
define float @fabs_select_nan_nan(float addrspace(1)* %out, i32 %c) {
+; CHECK-LABEL: @fabs_select_nan_nan(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0x7FF8000000000000, float 0x7FF8000100000000
+; CHECK-NEXT: ret float [[SELECT]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 0x7FF8000000000000, float 0x7FF8000100000000
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_negnan_nan(
-; CHECK: %select = select i1 %cmp, float 0xFFF8000000000000, float 0x7FF8000000000000
-; CHECK: %fabs = call float @llvm.fabs.f32(float %select)
define float @fabs_select_negnan_nan(float addrspace(1)* %out, i32 %c) {
+; CHECK-LABEL: @fabs_select_negnan_nan(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float 0x7FF8000000000000
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 0xFFF8000000000000, float 0x7FF8000000000000
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_negnan_negnan(
-; CHECK: %select = select i1 %cmp, float 0xFFF8000000000000, float 0x7FF8000100000000
-; CHECK: %fabs = call float @llvm.fabs.f32(float %select)
define float @fabs_select_negnan_negnan(float addrspace(1)* %out, i32 %c) {
+; CHECK-LABEL: @fabs_select_negnan_negnan(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float 0x7FF8000100000000
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 0xFFF8000000000000, float 0x7FF8000100000000
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_negnan_negzero(
-; CHECK: %select = select i1 %cmp, float 0xFFF8000000000000, float -0.000000e+00
-; CHECK: %fabs = call float @llvm.fabs.f32(float %select)
define float @fabs_select_negnan_negzero(float addrspace(1)* %out, i32 %c) {
+; CHECK-LABEL: @fabs_select_negnan_negzero(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float -0.000000e+00
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 0xFFF8000000000000, float -0.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_select_negnan_zero(
-; CHECK: %select = select i1 %cmp, float 0xFFF8000000000000, float 0.000000e+00
-; CHECK: %fabs = call float @llvm.fabs.f32(float %select)
define float @fabs_select_negnan_zero(float addrspace(1)* %out, i32 %c) {
+; CHECK-LABEL: @fabs_select_negnan_zero(
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
+; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float 0xFFF8000000000000, float 0.000000e+00
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%cmp = icmp eq i32 %c, 0
%select = select i1 %cmp, float 0xFFF8000000000000, float 0.0
%fabs = call float @llvm.fabs.f32(float %select)
ret float %fabs
}
-; CHECK-LABEL: @fabs_sqrt
-; CHECK: call float @llvm.sqrt.f32
-; CHECK: call float @llvm.fabs.f32
-define float @fabs_sqrt(float %a) {
; The fabs can't be eliminated because llvm.sqrt.f32 may return -0 or NaN with
; an arbitrary sign bit.
+define float @fabs_sqrt(float %a) {
+; CHECK-LABEL: @fabs_sqrt(
+; CHECK-NEXT: [[SQRT:%.*]] = call float @llvm.sqrt.f32(float [[A:%.*]])
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%sqrt = call float @llvm.sqrt.f32(float %a)
%fabs = call float @llvm.fabs.f32(float %sqrt)
ret float %fabs
}
-; CHECK-LABEL: @fabs_sqrt_nnan
-; CHECK: call nnan float @llvm.sqrt.f32
-; CHECK: call float @llvm.fabs.f32
-define float @fabs_sqrt_nnan(float %a) {
; The fabs can't be eliminated because the nnan sqrt may still return -0.
+define float @fabs_sqrt_nnan(float %a) {
+; CHECK-LABEL: @fabs_sqrt_nnan(
+; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @llvm.sqrt.f32(float [[A:%.*]])
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%sqrt = call nnan float @llvm.sqrt.f32(float %a)
%fabs = call float @llvm.fabs.f32(float %sqrt)
ret float %fabs
}
-; CHECK-LABEL: @fabs_sqrt_nsz
-; CHECK: call nsz float @llvm.sqrt.f32
-; CHECK: call float @llvm.fabs.f32
-define float @fabs_sqrt_nsz(float %a) {
; The fabs can't be eliminated because the nsz sqrt may still return NaN.
+define float @fabs_sqrt_nsz(float %a) {
+; CHECK-LABEL: @fabs_sqrt_nsz(
+; CHECK-NEXT: [[SQRT:%.*]] = call nsz float @llvm.sqrt.f32(float [[A:%.*]])
+; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SQRT]])
+; CHECK-NEXT: ret float [[FABS]]
+;
%sqrt = call nsz float @llvm.sqrt.f32(float %a)
%fabs = call float @llvm.fabs.f32(float %sqrt)
ret float %fabs
}
-; CHECK-LABEL: @fabs_sqrt_nnan_nsz
-; CHECK: call nnan nsz float @llvm.sqrt.f32
-; CHECK-NOT: call float @llvm.fabs.f32
-define float @fabs_sqrt_nnan_nsz(float %a) {
; The fabs can be eliminated because we're nsz and nnan.
+define float @fabs_sqrt_nnan_nsz(float %a) {
+; CHECK-LABEL: @fabs_sqrt_nnan_nsz(
+; CHECK-NEXT: [[SQRT:%.*]] = call nnan nsz float @llvm.sqrt.f32(float [[A:%.*]])
+; CHECK-NEXT: ret float [[SQRT]]
+;
%sqrt = call nnan nsz float @llvm.sqrt.f32(float %a)
%fabs = call float @llvm.fabs.f32(float %sqrt)
ret float %fabs
}
-; CHECK-LABEL: @fabs_sqrt_nnan_fabs
-; CHECK: call float @llvm.fabs.f32
-; CHECK: call nnan float @llvm.sqrt.f32
-; CHECK-NOT: call float @llvm.fabs.f32
-define float @fabs_sqrt_nnan_fabs(float %a) {
; The second fabs can be eliminated because the operand to sqrt cannot be -0.
+define float @fabs_sqrt_nnan_fabs(float %a) {
+; CHECK-LABEL: @fabs_sqrt_nnan_fabs(
+; CHECK-NEXT: [[B:%.*]] = call float @llvm.fabs.f32(float [[A:%.*]])
+; CHECK-NEXT: [[SQRT:%.*]] = call nnan float @llvm.sqrt.f32(float [[B]])
+; CHECK-NEXT: ret float [[SQRT]]
+;
%b = call float @llvm.fabs.f32(float %a)
%sqrt = call nnan float @llvm.sqrt.f32(float %b)
%fabs = call float @llvm.fabs.f32(float %sqrt)
Modified: llvm/trunk/test/Transforms/InstSimplify/mul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/mul.ll?rev=325037&r1=325036&r2=325037&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/mul.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/mul.ll Tue Feb 13 10:22:53 2018
@@ -9,3 +9,28 @@ define <2 x i1> @test1(<2 x i1> %a) {
%res = mul <2 x i1> %b, <i1 false, i1 true>
ret <2 x i1> %res
}
+
+define i32 @mul_by_1(i32 %A) {
+; CHECK-LABEL: @mul_by_1(
+; CHECK-NEXT: ret i32 [[A:%.*]]
+;
+ %B = mul i32 %A, 1
+ ret i32 %B
+}
+
+define i32 @mul_by_0(i32 %A) {
+; CHECK-LABEL: @mul_by_0(
+; CHECK-NEXT: ret i32 0
+;
+ %B = mul i32 %A, 0
+ ret i32 %B
+}
+
+define <16 x i8> @mul_by_0_vec(<16 x i8> %a) {
+; CHECK-LABEL: @mul_by_0_vec(
+; CHECK-NEXT: ret <16 x i8> zeroinitializer
+;
+ %b = mul <16 x i8> %a, zeroinitializer
+ ret <16 x i8> %b
+}
+
More information about the llvm-commits
mailing list