2002-05-02 17:01:39 +00:00
|
|
|
; Tests to make sure elimination of casts is working correctly
|
2009-10-12 07:18:14 +00:00
|
|
|
; RUN: opt < %s -instcombine -S | FileCheck %s
|
2009-11-10 07:23:37 +00:00
|
|
|
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128-n8:16:32:64"
|
2002-05-02 17:01:39 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
@inbuf = external global [32832 x i8] ; <[32832 x i8]*> [#uses=1]
|
2004-02-22 05:24:09 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test1(i32 %A) {
|
|
|
|
%c1 = bitcast i32 %A to i32 ; <i32> [#uses=1]
|
|
|
|
%c2 = bitcast i32 %c1 to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %c2
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret i32 %A
|
2002-08-02 18:48:09 +00:00
|
|
|
}
|
2002-05-02 17:01:39 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i64 @test2(i8 %A) {
|
|
|
|
%c1 = zext i8 %A to i16 ; <i16> [#uses=1]
|
|
|
|
%c2 = zext i16 %c1 to i32 ; <i32> [#uses=1]
|
|
|
|
%Ret = zext i32 %c2 to i64 ; <i64> [#uses=1]
|
|
|
|
ret i64 %Ret
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %Ret = zext i8 %A to i64
|
|
|
|
; CHECK: ret i64 %Ret
|
2002-08-02 18:48:09 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
; This function should just use bitwise AND
|
|
|
|
define i64 @test3(i64 %A) {
|
|
|
|
%c1 = trunc i64 %A to i8 ; <i8> [#uses=1]
|
|
|
|
%c2 = zext i8 %c1 to i64 ; <i64> [#uses=1]
|
|
|
|
ret i64 %c2
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c2 = and i64 %A, 255
|
|
|
|
; CHECK: ret i64 %c2
|
2002-08-02 18:48:09 +00:00
|
|
|
}
|
2002-08-15 16:13:29 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test4(i32 %A, i32 %B) {
|
|
|
|
%COND = icmp slt i32 %A, %B ; <i1> [#uses=1]
|
|
|
|
; Booleans are unsigned integrals
|
|
|
|
%c = zext i1 %COND to i8 ; <i8> [#uses=1]
|
|
|
|
; for the cast elim purpose
|
|
|
|
%result = zext i8 %c to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %result
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %COND = icmp slt i32 %A, %B
|
|
|
|
; CHECK: %result = zext i1 %COND to i32
|
|
|
|
; CHECK: ret i32 %result
|
2002-08-15 16:13:29 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test5(i1 %B) {
|
|
|
|
; This cast should get folded into
|
|
|
|
%c = zext i1 %B to i8 ; <i8> [#uses=1]
|
|
|
|
; this cast
|
|
|
|
%result = zext i8 %c to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %result
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %result = zext i1 %B to i32
|
|
|
|
; CHECK: ret i32 %result
|
2002-08-15 16:13:29 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test6(i64 %A) {
|
|
|
|
%c1 = trunc i64 %A to i32 ; <i32> [#uses=1]
|
|
|
|
%res = bitcast i32 %c1 to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %res
|
2010-01-05 22:21:18 +00:00
|
|
|
; CHECK: trunc i64 %A to i32
|
|
|
|
; CHECK-NEXT: ret i32
|
2002-08-15 16:13:29 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i64 @test7(i1 %A) {
|
|
|
|
%c1 = zext i1 %A to i32 ; <i32> [#uses=1]
|
|
|
|
%res = sext i32 %c1 to i64 ; <i64> [#uses=1]
|
|
|
|
ret i64 %res
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %res = zext i1 %A to i64
|
|
|
|
; CHECK: ret i64 %res
|
2002-08-15 16:13:29 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i64 @test8(i8 %A) {
|
|
|
|
%c1 = sext i8 %A to i64 ; <i64> [#uses=1]
|
|
|
|
%res = bitcast i64 %c1 to i64 ; <i64> [#uses=1]
|
|
|
|
ret i64 %res
|
2010-01-05 22:21:18 +00:00
|
|
|
; CHECK: = sext i8 %A to i64
|
|
|
|
; CHECK-NEXT: ret i64
|
2002-08-15 16:13:29 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i16 @test9(i16 %A) {
|
|
|
|
%c1 = sext i16 %A to i32 ; <i32> [#uses=1]
|
|
|
|
%c2 = trunc i32 %c1 to i16 ; <i16> [#uses=1]
|
|
|
|
ret i16 %c2
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret i16 %A
|
2002-09-23 23:39:17 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i16 @test10(i16 %A) {
|
|
|
|
%c1 = sext i16 %A to i32 ; <i32> [#uses=1]
|
|
|
|
%c2 = trunc i32 %c1 to i16 ; <i16> [#uses=1]
|
|
|
|
ret i16 %c2
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret i16 %A
|
2002-09-23 23:39:17 +00:00
|
|
|
}
|
2003-06-23 21:48:26 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
declare void @varargs(i32, ...)
|
2003-10-07 22:53:46 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define void @test11(i32* %P) {
|
|
|
|
%c = bitcast i32* %P to i16* ; <i16*> [#uses=1]
|
|
|
|
call void (i32, ...)* @varargs( i32 5, i16* %c )
|
|
|
|
ret void
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: call void (i32, ...)* @varargs(i32 5, i32* %P)
|
|
|
|
; CHECK: ret void
|
2003-10-07 22:53:46 +00:00
|
|
|
}
|
2003-11-02 05:56:58 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32* @test12() {
|
2009-09-25 18:11:52 +00:00
|
|
|
%p = malloc [4 x i8] ; <[4 x i8]*> [#uses=1]
|
|
|
|
%c = bitcast [4 x i8]* %p to i32* ; <i32*> [#uses=1]
|
|
|
|
ret i32* %c
|
2009-11-23 16:22:21 +00:00
|
|
|
; CHECK: %malloccall = tail call i8* @malloc(i32 4)
|
2009-10-17 00:00:19 +00:00
|
|
|
; CHECK: ret i32* %c
|
2003-11-02 05:56:58 +00:00
|
|
|
}
|
2009-10-12 07:18:14 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i8* @test13(i64 %A) {
|
|
|
|
%c = getelementptr [0 x i8]* bitcast ([32832 x i8]* @inbuf to [0 x i8]*), i64 0, i64 %A ; <i8*> [#uses=1]
|
|
|
|
ret i8* %c
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c = getelementptr [32832 x i8]* @inbuf, i64 0, i64 %A
|
|
|
|
; CHECK: ret i8* %c
|
2004-02-22 05:24:09 +00:00
|
|
|
}
|
2004-02-23 07:16:03 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i1 @test14(i8 %A) {
|
|
|
|
%c = bitcast i8 %A to i8 ; <i8> [#uses=1]
|
|
|
|
%X = icmp ult i8 %c, -128 ; <i1> [#uses=1]
|
|
|
|
ret i1 %X
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %X = icmp sgt i8 %A, -1
|
|
|
|
; CHECK: ret i1 %X
|
2004-02-23 07:16:03 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
|
2006-12-23 06:05:41 +00:00
|
|
|
; This just won't occur when there's no difference between ubyte and sbyte
|
|
|
|
;bool %test15(ubyte %A) {
|
|
|
|
; %c = cast ubyte %A to sbyte
|
|
|
|
; %X = setlt sbyte %c, 0 ; setgt %A, 127
|
|
|
|
; ret bool %X
|
|
|
|
;}
|
2004-02-23 07:16:03 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i1 @test16(i32* %P) {
|
|
|
|
%c = icmp ne i32* %P, null ; <i1> [#uses=1]
|
|
|
|
ret i1 %c
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c = icmp ne i32* %P, null
|
|
|
|
; CHECK: ret i1 %c
|
2004-05-25 04:28:43 +00:00
|
|
|
}
|
2004-07-20 00:57:21 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i16 @test17(i1 %tmp3) {
|
|
|
|
%c = zext i1 %tmp3 to i32 ; <i32> [#uses=1]
|
|
|
|
%t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
|
|
|
|
ret i16 %t86
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %t86 = zext i1 %tmp3 to i16
|
|
|
|
; CHECK: ret i16 %t86
|
2004-07-20 00:57:21 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i16 @test18(i8 %tmp3) {
|
|
|
|
%c = sext i8 %tmp3 to i32 ; <i32> [#uses=1]
|
|
|
|
%t86 = trunc i32 %c to i16 ; <i16> [#uses=1]
|
|
|
|
ret i16 %t86
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %t86 = sext i8 %tmp3 to i16
|
|
|
|
; CHECK: ret i16 %t86
|
2004-07-20 00:57:21 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i1 @test19(i32 %X) {
|
|
|
|
%c = sext i32 %X to i64 ; <i64> [#uses=1]
|
|
|
|
%Z = icmp slt i64 %c, 12345 ; <i1> [#uses=1]
|
|
|
|
ret i1 %Z
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %Z = icmp slt i32 %X, 12345
|
|
|
|
; CHECK: ret i1 %Z
|
2004-09-29 03:18:20 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i1 @test20(i1 %B) {
|
|
|
|
%c = zext i1 %B to i32 ; <i32> [#uses=1]
|
|
|
|
%D = icmp slt i32 %c, -1 ; <i1> [#uses=1]
|
|
|
|
;; false
|
|
|
|
ret i1 %D
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret i1 false
|
2004-09-29 03:18:20 +00:00
|
|
|
}
|
2005-01-01 16:13:43 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test21(i32 %X) {
|
|
|
|
%c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
|
|
|
|
;; sext -> zext -> and -> nop
|
|
|
|
%c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
|
|
|
|
%RV = and i32 %c2, 255 ; <i32> [#uses=1]
|
|
|
|
ret i32 %RV
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c21 = and i32 %X, 255
|
|
|
|
; CHECK: ret i32 %c21
|
2005-01-01 16:13:43 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test22(i32 %X) {
|
|
|
|
%c1 = trunc i32 %X to i8 ; <i8> [#uses=1]
|
|
|
|
;; sext -> zext -> and -> nop
|
|
|
|
%c2 = sext i8 %c1 to i32 ; <i32> [#uses=1]
|
|
|
|
%RV = shl i32 %c2, 24 ; <i32> [#uses=1]
|
|
|
|
ret i32 %RV
|
2010-01-10 07:40:50 +00:00
|
|
|
; CHECK: shl i32 %X, 24
|
|
|
|
; CHECK-NEXT: ret i32
|
2005-01-01 16:13:43 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test23(i32 %X) {
|
|
|
|
;; Turn into an AND even though X
|
|
|
|
%c1 = trunc i32 %X to i16 ; <i16> [#uses=1]
|
|
|
|
;; and Z are signed.
|
|
|
|
%c2 = zext i16 %c1 to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %c2
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c2 = and i32 %X, 65535
|
|
|
|
; CHECK: ret i32 %c2
|
2005-01-01 16:13:43 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i1 @test24(i1 %C) {
|
|
|
|
%X = select i1 %C, i32 14, i32 1234 ; <i32> [#uses=1]
|
|
|
|
;; Fold cast into select
|
|
|
|
%c = icmp ne i32 %X, 0 ; <i1> [#uses=1]
|
|
|
|
ret i1 %c
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret i1 true
|
2005-01-01 16:13:43 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define void @test25(i32** %P) {
|
|
|
|
%c = bitcast i32** %P to float** ; <float**> [#uses=1]
|
|
|
|
;; Fold cast into null
|
|
|
|
store float* null, float** %c
|
2005-01-31 05:51:18 +00:00
|
|
|
ret void
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: store i32* null, i32** %P
|
|
|
|
; CHECK: ret void
|
2005-01-31 05:51:18 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test26(float %F) {
|
|
|
|
;; no need to cast from float->double.
|
|
|
|
%c = fpext float %F to double ; <double> [#uses=1]
|
|
|
|
%D = fptosi double %c to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %D
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %D = fptosi float %F to i32
|
|
|
|
; CHECK: ret i32 %D
|
2006-01-19 07:39:20 +00:00
|
|
|
}
|
2006-04-12 18:07:41 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define [4 x float]* @test27([9 x [4 x float]]* %A) {
|
|
|
|
%c = bitcast [9 x [4 x float]]* %A to [4 x float]* ; <[4 x float]*> [#uses=1]
|
|
|
|
ret [4 x float]* %c
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c = getelementptr inbounds [9 x [4 x float]]* %A, i64 0, i64 0
|
|
|
|
; CHECK: ret [4 x float]* %c
|
2006-04-12 18:07:41 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define float* @test28([4 x float]* %A) {
|
|
|
|
%c = bitcast [4 x float]* %A to float* ; <float*> [#uses=1]
|
|
|
|
ret float* %c
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c = getelementptr inbounds [4 x float]* %A, i64 0, i64 0
|
|
|
|
; CHECK: ret float* %c
|
2006-04-12 18:07:41 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test29(i32 %c1, i32 %c2) {
|
|
|
|
%tmp1 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
|
|
|
|
%tmp4.mask = trunc i32 %c2 to i8 ; <i8> [#uses=1]
|
|
|
|
%tmp = or i8 %tmp4.mask, %tmp1 ; <i8> [#uses=1]
|
|
|
|
%tmp10 = zext i8 %tmp to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %tmp10
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %tmp2 = or i32 %c2, %c1
|
|
|
|
; CHECK: %tmp10 = and i32 %tmp2, 255
|
|
|
|
; CHECK: ret i32 %tmp10
|
2006-05-05 06:38:40 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test30(i32 %c1) {
|
|
|
|
%c2 = trunc i32 %c1 to i8 ; <i8> [#uses=1]
|
|
|
|
%c3 = xor i8 %c2, 1 ; <i8> [#uses=1]
|
|
|
|
%c4 = zext i8 %c3 to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %c4
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %c3 = and i32 %c1, 255
|
|
|
|
; CHECK: %c4 = xor i32 %c3, 1
|
|
|
|
; CHECK: ret i32 %c4
|
2006-05-13 02:00:07 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i1 @test31(i64 %A) {
|
|
|
|
%B = trunc i64 %A to i32 ; <i32> [#uses=1]
|
|
|
|
%C = and i32 %B, 42 ; <i32> [#uses=1]
|
|
|
|
%D = icmp eq i32 %C, 10 ; <i1> [#uses=1]
|
|
|
|
ret i1 %D
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %C1 = and i64 %A, 42
|
|
|
|
; CHECK: %D = icmp eq i64 %C1, 10
|
|
|
|
; CHECK: ret i1 %D
|
2006-09-18 05:25:10 +00:00
|
|
|
}
|
2006-05-13 02:00:07 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define void @test32(double** %tmp) {
|
|
|
|
%tmp8 = malloc [16 x i8] ; <[16 x i8]*> [#uses=1]
|
|
|
|
%tmp8.upgrd.1 = bitcast [16 x i8]* %tmp8 to double* ; <double*> [#uses=1]
|
|
|
|
store double* %tmp8.upgrd.1, double** %tmp
|
2006-10-01 19:39:45 +00:00
|
|
|
ret void
|
2009-11-23 16:22:21 +00:00
|
|
|
; CHECK: %malloccall = tail call i8* @malloc(i32 16)
|
2009-10-17 00:00:19 +00:00
|
|
|
; CHECK: %tmp8.upgrd.1 = bitcast i8* %malloccall to double*
|
|
|
|
; CHECK: store double* %tmp8.upgrd.1, double** %tmp
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret void
|
2006-10-01 19:39:45 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i32 @test33(i32 %c1) {
|
|
|
|
%x = bitcast i32 %c1 to float ; <float> [#uses=1]
|
|
|
|
%y = bitcast float %x to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %y
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret i32 %c1
|
2006-11-27 01:05:10 +00:00
|
|
|
}
|
2006-11-29 07:03:00 +00:00
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i16 @test34(i16 %a) {
|
|
|
|
%c1 = zext i16 %a to i32 ; <i32> [#uses=1]
|
|
|
|
%tmp21 = lshr i32 %c1, 8 ; <i32> [#uses=1]
|
|
|
|
%c2 = trunc i32 %tmp21 to i16 ; <i16> [#uses=1]
|
|
|
|
ret i16 %c2
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %tmp21 = lshr i16 %a, 8
|
|
|
|
; CHECK: ret i16 %tmp21
|
2006-11-29 07:03:00 +00:00
|
|
|
}
|
|
|
|
|
2008-03-25 04:26:08 +00:00
|
|
|
define i16 @test35(i16 %a) {
|
|
|
|
%c1 = bitcast i16 %a to i16 ; <i16> [#uses=1]
|
|
|
|
%tmp2 = lshr i16 %c1, 8 ; <i16> [#uses=1]
|
|
|
|
%c2 = bitcast i16 %tmp2 to i16 ; <i16> [#uses=1]
|
|
|
|
ret i16 %c2
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %tmp2 = lshr i16 %a, 8
|
|
|
|
; CHECK: ret i16 %tmp2
|
2006-11-29 07:17:32 +00:00
|
|
|
}
|
|
|
|
|
Implement rdar://6480391, extending of equality icmp's to avoid a truncation.
I noticed this in the code compiled for a routine using std::map, which produced
this code:
%25 = tail call i32 @memcmp(i8* %24, i8* %23, i32 6) nounwind readonly
%.lobit.i = lshr i32 %25, 31 ; <i32> [#uses=1]
%tmp.i = trunc i32 %.lobit.i to i8 ; <i8> [#uses=1]
%toBool = icmp eq i8 %tmp.i, 0 ; <i1> [#uses=1]
br i1 %toBool, label %bb3, label %bb4
which compiled to:
call L_memcmp$stub
shrl $31, %eax
testb %al, %al
jne LBB1_11 ##
with this change, we compile it to:
call L_memcmp$stub
testl %eax, %eax
js LBB1_11
This triggers all the time in common code, with patters like this:
%169 = and i32 %ply, 1 ; <i32> [#uses=1]
%170 = trunc i32 %169 to i8 ; <i8> [#uses=1]
%toBool = icmp ne i8 %170, 0 ; <i1> [#uses=1]
%7 = lshr i32 %6, 24 ; <i32> [#uses=1]
%9 = trunc i32 %7 to i8 ; <i8> [#uses=1]
%10 = icmp ne i8 %9, 0 ; <i1> [#uses=1]
etc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61985 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-09 07:47:06 +00:00
|
|
|
; icmp sgt i32 %a, -1
|
|
|
|
; rdar://6480391
|
|
|
|
define i1 @test36(i32 %a) {
|
|
|
|
%b = lshr i32 %a, 31
|
|
|
|
%c = trunc i32 %b to i8
|
|
|
|
%d = icmp eq i8 %c, 0
|
|
|
|
ret i1 %d
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %d = icmp sgt i32 %a, -1
|
|
|
|
; CHECK: ret i1 %d
|
Implement rdar://6480391, extending of equality icmp's to avoid a truncation.
I noticed this in the code compiled for a routine using std::map, which produced
this code:
%25 = tail call i32 @memcmp(i8* %24, i8* %23, i32 6) nounwind readonly
%.lobit.i = lshr i32 %25, 31 ; <i32> [#uses=1]
%tmp.i = trunc i32 %.lobit.i to i8 ; <i8> [#uses=1]
%toBool = icmp eq i8 %tmp.i, 0 ; <i1> [#uses=1]
br i1 %toBool, label %bb3, label %bb4
which compiled to:
call L_memcmp$stub
shrl $31, %eax
testb %al, %al
jne LBB1_11 ##
with this change, we compile it to:
call L_memcmp$stub
testl %eax, %eax
js LBB1_11
This triggers all the time in common code, with patters like this:
%169 = and i32 %ply, 1 ; <i32> [#uses=1]
%170 = trunc i32 %169 to i8 ; <i8> [#uses=1]
%toBool = icmp ne i8 %170, 0 ; <i1> [#uses=1]
%7 = lshr i32 %6, 24 ; <i32> [#uses=1]
%9 = trunc i32 %7 to i8 ; <i8> [#uses=1]
%10 = icmp ne i8 %9, 0 ; <i1> [#uses=1]
etc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61985 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-09 07:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
; ret i1 false
|
|
|
|
define i1 @test37(i32 %a) {
|
|
|
|
%b = lshr i32 %a, 31
|
|
|
|
%c = or i32 %b, 512
|
|
|
|
%d = trunc i32 %c to i8
|
|
|
|
%e = icmp eq i8 %d, 11
|
|
|
|
ret i1 %e
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: ret i1 false
|
Implement rdar://6480391, extending of equality icmp's to avoid a truncation.
I noticed this in the code compiled for a routine using std::map, which produced
this code:
%25 = tail call i32 @memcmp(i8* %24, i8* %23, i32 6) nounwind readonly
%.lobit.i = lshr i32 %25, 31 ; <i32> [#uses=1]
%tmp.i = trunc i32 %.lobit.i to i8 ; <i8> [#uses=1]
%toBool = icmp eq i8 %tmp.i, 0 ; <i1> [#uses=1]
br i1 %toBool, label %bb3, label %bb4
which compiled to:
call L_memcmp$stub
shrl $31, %eax
testb %al, %al
jne LBB1_11 ##
with this change, we compile it to:
call L_memcmp$stub
testl %eax, %eax
js LBB1_11
This triggers all the time in common code, with patters like this:
%169 = and i32 %ply, 1 ; <i32> [#uses=1]
%170 = trunc i32 %169 to i8 ; <i8> [#uses=1]
%toBool = icmp ne i8 %170, 0 ; <i1> [#uses=1]
%7 = lshr i32 %6, 24 ; <i32> [#uses=1]
%9 = trunc i32 %7 to i8 ; <i8> [#uses=1]
%10 = icmp ne i8 %9, 0 ; <i1> [#uses=1]
etc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61985 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-09 07:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 02:11:43 +00:00
|
|
|
define i64 @test38(i32 %a) {
|
|
|
|
%1 = icmp eq i32 %a, -2
|
|
|
|
%2 = zext i1 %1 to i8
|
|
|
|
%3 = xor i8 %2, 1
|
|
|
|
%4 = zext i8 %3 to i64
|
|
|
|
ret i64 %4
|
2009-10-12 07:18:14 +00:00
|
|
|
; CHECK: %1 = icmp ne i32 %a, -2
|
|
|
|
; CHECK: %2 = zext i1 %1 to i64
|
|
|
|
; CHECK: ret i64 %2
|
2009-01-16 02:11:43 +00:00
|
|
|
}
|
2010-01-05 21:48:13 +00:00
|
|
|
|
|
|
|
define i16 @test39(i16 %a) {
|
|
|
|
%tmp = zext i16 %a to i32
|
|
|
|
%tmp21 = lshr i32 %tmp, 8
|
|
|
|
%tmp5 = shl i32 %tmp, 8
|
|
|
|
%tmp.upgrd.32 = or i32 %tmp21, %tmp5
|
|
|
|
%tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
|
|
|
|
ret i16 %tmp.upgrd.3
|
|
|
|
; CHECK: @test39
|
|
|
|
; CHECK: %tmp.upgrd.32 = call i16 @llvm.bswap.i16(i16 %a)
|
|
|
|
; CHECK: ret i16 %tmp.upgrd.32
|
|
|
|
}
|
|
|
|
|
|
|
|
define i16 @test40(i16 %a) {
|
|
|
|
%tmp = zext i16 %a to i32
|
|
|
|
%tmp21 = lshr i32 %tmp, 9
|
|
|
|
%tmp5 = shl i32 %tmp, 8
|
|
|
|
%tmp.upgrd.32 = or i32 %tmp21, %tmp5
|
|
|
|
%tmp.upgrd.3 = trunc i32 %tmp.upgrd.32 to i16
|
|
|
|
ret i16 %tmp.upgrd.3
|
|
|
|
; CHECK: @test40
|
|
|
|
; CHECK: %tmp21 = lshr i16 %a, 9
|
|
|
|
; CHECK: %tmp5 = shl i16 %a, 8
|
|
|
|
; CHECK: %tmp.upgrd.32 = or i16 %tmp21, %tmp5
|
|
|
|
; CHECK: ret i16 %tmp.upgrd.32
|
|
|
|
}
|
|
|
|
|
|
|
|
; PR1263
|
|
|
|
define i32* @test41(i32* %tmp1) {
|
|
|
|
%tmp64 = bitcast i32* %tmp1 to { i32 }*
|
|
|
|
%tmp65 = getelementptr { i32 }* %tmp64, i32 0, i32 0
|
|
|
|
ret i32* %tmp65
|
|
|
|
; CHECK: @test41
|
|
|
|
; CHECK: ret i32* %tmp1
|
|
|
|
}
|
|
|
|
|
2010-01-05 21:54:09 +00:00
|
|
|
define i32 @test42(i32 %X) {
|
|
|
|
%Y = trunc i32 %X to i8 ; <i8> [#uses=1]
|
|
|
|
%Z = zext i8 %Y to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %Z
|
|
|
|
; CHECK: @test42
|
|
|
|
; CHECK: %Z = and i32 %X, 255
|
|
|
|
}
|
2010-01-05 21:48:13 +00:00
|
|
|
|
2010-01-06 01:56:21 +00:00
|
|
|
; rdar://6598839
|
|
|
|
define zeroext i64 @test43(i8 zeroext %on_off) nounwind readonly {
|
|
|
|
%A = zext i8 %on_off to i32
|
|
|
|
%B = add i32 %A, -1
|
|
|
|
%C = sext i32 %B to i64
|
|
|
|
ret i64 %C ;; Should be (add (zext i8 -> i64), -1)
|
|
|
|
; CHECK: @test43
|
|
|
|
; CHECK-NEXT: %A = zext i8 %on_off to i64
|
|
|
|
; CHECK-NEXT: %B = add i64 %A, -1
|
|
|
|
; CHECK-NEXT: ret i64 %B
|
|
|
|
}
|
2010-01-07 23:41:00 +00:00
|
|
|
|
|
|
|
define i64 @test44(i8 %T) {
|
|
|
|
%A = zext i8 %T to i16
|
|
|
|
%B = or i16 %A, 1234
|
|
|
|
%C = zext i16 %B to i64
|
|
|
|
ret i64 %C
|
|
|
|
; CHECK: @test44
|
|
|
|
; CHECK-NEXT: %A = zext i8 %T to i64
|
|
|
|
; CHECK-NEXT: %B = or i64 %A, 1234
|
|
|
|
; CHECK-NEXT: ret i64 %B
|
|
|
|
}
|
2010-01-10 02:22:12 +00:00
|
|
|
|
|
|
|
define i64 @test45(i8 %A, i64 %Q) {
|
|
|
|
%D = trunc i64 %Q to i32 ;; should be removed
|
|
|
|
%B = sext i8 %A to i32
|
|
|
|
%C = or i32 %B, %D
|
|
|
|
%E = zext i32 %C to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test45
|
|
|
|
; CHECK-NEXT: %B = sext i8 %A to i64
|
|
|
|
; CHECK-NEXT: %C = or i64 %B, %Q
|
|
|
|
; CHECK-NEXT: %E = and i64 %C, 4294967295
|
|
|
|
; CHECK-NEXT: ret i64 %E
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define i64 @test46(i64 %A) {
|
|
|
|
%B = trunc i64 %A to i32
|
|
|
|
%C = and i32 %B, 42
|
|
|
|
%D = shl i32 %C, 8
|
|
|
|
%E = zext i32 %D to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test46
|
|
|
|
; CHECK-NEXT: %C = shl i64 %A, 8
|
|
|
|
; CHECK-NEXT: %D = and i64 %C, 10752
|
|
|
|
; CHECK-NEXT: ret i64 %D
|
|
|
|
}
|
|
|
|
|
2010-01-10 02:39:31 +00:00
|
|
|
define i64 @test47(i8 %A) {
|
|
|
|
%B = sext i8 %A to i32
|
|
|
|
%C = or i32 %B, 42
|
|
|
|
%E = zext i32 %C to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test47
|
|
|
|
; CHECK-NEXT: %B = sext i8 %A to i64
|
|
|
|
; CHECK-NEXT: %C = or i64 %B, 42
|
|
|
|
; CHECK-NEXT: %E = and i64 %C, 4294967295
|
|
|
|
; CHECK-NEXT: ret i64 %E
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test48(i8 %A, i8 %a) {
|
|
|
|
%b = zext i8 %a to i32
|
|
|
|
%B = zext i8 %A to i32
|
|
|
|
%C = shl i32 %B, 8
|
|
|
|
%D = or i32 %C, %b
|
|
|
|
%E = zext i32 %D to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test48
|
|
|
|
; CHECK-NEXT: %b = zext i8 %a to i64
|
|
|
|
; CHECK-NEXT: %B = zext i8 %A to i64
|
|
|
|
; CHECK-NEXT: %C = shl i64 %B, 8
|
|
|
|
; CHECK-NEXT: %D = or i64 %C, %b
|
|
|
|
; CHECK-NEXT: ret i64 %D
|
|
|
|
}
|
2010-01-10 02:22:12 +00:00
|
|
|
|
2010-01-10 07:40:50 +00:00
|
|
|
define i64 @test49(i64 %A) {
|
|
|
|
%B = trunc i64 %A to i32
|
|
|
|
%C = or i32 %B, 1
|
|
|
|
%D = sext i32 %C to i64
|
|
|
|
ret i64 %D
|
|
|
|
; CHECK: @test49
|
|
|
|
; CHECK-NEXT: %C = shl i64 %A, 32
|
|
|
|
; CHECK-NEXT: ashr i64 %C, 32
|
|
|
|
; CHECK-NEXT: %D = or i64 {{.*}}, 1
|
|
|
|
; CHECK-NEXT: ret i64 %D
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test50(i64 %A) {
|
|
|
|
%a = lshr i64 %A, 2
|
|
|
|
%B = trunc i64 %a to i32
|
|
|
|
%D = add i32 %B, -1
|
|
|
|
%E = sext i32 %D to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test50
|
|
|
|
; CHECK-NEXT: shl i64 %A, 30
|
|
|
|
; CHECK-NEXT: add i64 {{.*}}, -4294967296
|
|
|
|
; CHECK-NEXT: %E = ashr i64 {{.*}}, 32
|
|
|
|
; CHECK-NEXT: ret i64 %E
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test51(i64 %A, i1 %cond) {
|
|
|
|
%B = trunc i64 %A to i32
|
|
|
|
%C = and i32 %B, -2
|
|
|
|
%D = or i32 %B, 1
|
|
|
|
%E = select i1 %cond, i32 %C, i32 %D
|
|
|
|
%F = sext i32 %E to i64
|
|
|
|
ret i64 %F
|
|
|
|
; CHECK: @test51
|
2010-01-11 23:18:33 +00:00
|
|
|
|
|
|
|
; FIXME: disabled, see PR5997
|
|
|
|
; HECK-NEXT: %C = and i64 %A, 4294967294
|
|
|
|
; HECK-NEXT: %D = or i64 %A, 1
|
|
|
|
; HECK-NEXT: %E = select i1 %cond, i64 %C, i64 %D
|
|
|
|
; HECK-NEXT: %sext = shl i64 %E, 32
|
|
|
|
; HECK-NEXT: %F = ashr i64 %sext, 32
|
|
|
|
; HECK-NEXT: ret i64 %F
|
2010-01-10 07:40:50 +00:00
|
|
|
}
|
|
|
|
|
2010-01-10 20:25:54 +00:00
|
|
|
define i32 @test52(i64 %A) {
|
|
|
|
%B = trunc i64 %A to i16
|
|
|
|
%C = or i16 %B, -32574
|
|
|
|
%D = and i16 %C, -25350
|
|
|
|
%E = zext i16 %D to i32
|
|
|
|
ret i32 %E
|
|
|
|
; CHECK: @test52
|
|
|
|
; CHECK-NEXT: %B = trunc i64 %A to i32
|
|
|
|
; CHECK-NEXT: %C = or i32 %B, 32962
|
|
|
|
; CHECK-NEXT: %D = and i32 %C, 40186
|
|
|
|
; CHECK-NEXT: ret i32 %D
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test53(i32 %A) {
|
|
|
|
%B = trunc i32 %A to i16
|
|
|
|
%C = or i16 %B, -32574
|
|
|
|
%D = and i16 %C, -25350
|
|
|
|
%E = zext i16 %D to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test53
|
|
|
|
; CHECK-NEXT: %B = zext i32 %A to i64
|
|
|
|
; CHECK-NEXT: %C = or i64 %B, 32962
|
|
|
|
; CHECK-NEXT: %D = and i64 %C, 40186
|
|
|
|
; CHECK-NEXT: ret i64 %D
|
|
|
|
}
|
2010-01-10 20:30:41 +00:00
|
|
|
|
|
|
|
define i32 @test54(i64 %A) {
|
|
|
|
%B = trunc i64 %A to i16
|
|
|
|
%C = or i16 %B, -32574
|
|
|
|
%D = and i16 %C, -25350
|
|
|
|
%E = sext i16 %D to i32
|
|
|
|
ret i32 %E
|
|
|
|
; CHECK: @test54
|
|
|
|
; CHECK-NEXT: %B = trunc i64 %A to i32
|
|
|
|
; CHECK-NEXT: %C = or i32 %B, -32574
|
|
|
|
; CHECK-NEXT: %D = and i32 %C, -25350
|
|
|
|
; CHECK-NEXT: ret i32 %D
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test55(i32 %A) {
|
|
|
|
%B = trunc i32 %A to i16
|
|
|
|
%C = or i16 %B, -32574
|
|
|
|
%D = and i16 %C, -25350
|
|
|
|
%E = sext i16 %D to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test55
|
|
|
|
; CHECK-NEXT: %B = zext i32 %A to i64
|
|
|
|
; CHECK-NEXT: %C = or i64 %B, -32574
|
|
|
|
; CHECK-NEXT: %D = and i64 %C, -25350
|
|
|
|
; CHECK-NEXT: ret i64 %D
|
2010-01-11 03:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test56(i16 %A) nounwind {
|
|
|
|
%tmp353 = sext i16 %A to i32
|
|
|
|
%tmp354 = lshr i32 %tmp353, 5
|
|
|
|
%tmp355 = zext i32 %tmp354 to i64
|
|
|
|
ret i64 %tmp355
|
|
|
|
; CHECK: @test56
|
|
|
|
; CHECK-NEXT: %tmp353 = sext i16 %A to i64
|
|
|
|
; CHECK-NEXT: %tmp354 = lshr i64 %tmp353, 5
|
|
|
|
; CHECK-NEXT: %tmp355 = and i64 %tmp354, 134217727
|
|
|
|
; CHECK-NEXT: ret i64 %tmp355
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test57(i64 %A) nounwind {
|
|
|
|
%B = trunc i64 %A to i32
|
|
|
|
%C = lshr i32 %B, 8
|
|
|
|
%E = zext i32 %C to i64
|
|
|
|
ret i64 %E
|
|
|
|
; CHECK: @test57
|
|
|
|
; CHECK-NEXT: %C = lshr i64 %A, 8
|
|
|
|
; CHECK-NEXT: %E = and i64 %C, 16777215
|
|
|
|
; CHECK-NEXT: ret i64 %E
|
|
|
|
}
|
Extend CanEvaluateZExtd to handle and/or/xor more aggressively in the
BitsToClear case. This allows it to promote expressions which have an
and/or/xor after the lshr, promoting cases like test2 (from PR4216)
and test3 (random extample extracted from a spec benchmark).
clang now compiles the code in PR4216 into:
_test_bitfield: ## @test_bitfield
movl %edi, %eax
orl $194, %eax
movl $4294902010, %ecx
andq %rax, %rcx
orl $32768, %edi
andq $39936, %rdi
movq %rdi, %rax
orq %rcx, %rax
ret
instead of:
_test_bitfield: ## @test_bitfield
movl %edi, %eax
orl $194, %eax
movl $4294902010, %ecx
andq %rax, %rcx
shrl $8, %edi
orl $128, %edi
shlq $8, %rdi
andq $39936, %rdi
movq %rdi, %rax
orq %rcx, %rax
ret
which is still not great, but is progress.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93145 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-11 04:05:13 +00:00
|
|
|
|
|
|
|
define i64 @test58(i64 %A) nounwind {
|
|
|
|
%B = trunc i64 %A to i32
|
|
|
|
%C = lshr i32 %B, 8
|
|
|
|
%D = or i32 %C, 128
|
|
|
|
%E = zext i32 %D to i64
|
|
|
|
ret i64 %E
|
|
|
|
|
|
|
|
; CHECK: @test58
|
|
|
|
; CHECK-NEXT: %C = lshr i64 %A, 8
|
|
|
|
; CHECK-NEXT: %D = or i64 %C, 128
|
|
|
|
; CHECK-NEXT: %E = and i64 %D, 16777215
|
|
|
|
; CHECK-NEXT: ret i64 %E
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test59(i8 %A, i8 %B) nounwind {
|
|
|
|
%C = zext i8 %A to i32
|
|
|
|
%D = shl i32 %C, 4
|
|
|
|
%E = and i32 %D, 48
|
|
|
|
%F = zext i8 %B to i32
|
|
|
|
%G = lshr i32 %F, 4
|
|
|
|
%H = or i32 %G, %E
|
|
|
|
%I = zext i32 %H to i64
|
|
|
|
ret i64 %I
|
|
|
|
; CHECK: @test59
|
|
|
|
; CHECK-NEXT: %C = zext i8 %A to i64
|
|
|
|
; CHECK-NOT: i32
|
|
|
|
; CHECK: %F = zext i8 %B to i64
|
|
|
|
; CHECK-NOT: i32
|
|
|
|
; CHECK: ret i64 %H
|
|
|
|
}
|
2010-05-08 21:50:26 +00:00
|
|
|
|
|
|
|
define <3 x i32> @test60(<4 x i32> %call4) nounwind {
|
|
|
|
%tmp11 = bitcast <4 x i32> %call4 to i128
|
|
|
|
%tmp9 = trunc i128 %tmp11 to i96
|
|
|
|
%tmp10 = bitcast i96 %tmp9 to <3 x i32>
|
|
|
|
ret <3 x i32> %tmp10
|
|
|
|
|
|
|
|
; CHECK: @test60
|
|
|
|
; CHECK-NEXT: shufflevector
|
|
|
|
; CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define <4 x i32> @test61(<3 x i32> %call4) nounwind {
|
|
|
|
%tmp11 = bitcast <3 x i32> %call4 to i96
|
|
|
|
%tmp9 = zext i96 %tmp11 to i128
|
|
|
|
%tmp10 = bitcast i128 %tmp9 to <4 x i32>
|
|
|
|
ret <4 x i32> %tmp10
|
|
|
|
; CHECK: @test61
|
|
|
|
; CHECK-NEXT: shufflevector
|
|
|
|
; CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
|
|
|
define <4 x i32> @test62(<3 x float> %call4) nounwind {
|
|
|
|
%tmp11 = bitcast <3 x float> %call4 to i96
|
|
|
|
%tmp9 = zext i96 %tmp11 to i128
|
|
|
|
%tmp10 = bitcast i128 %tmp9 to <4 x i32>
|
|
|
|
ret <4 x i32> %tmp10
|
|
|
|
; CHECK: @test62
|
|
|
|
; CHECK-NEXT: bitcast
|
|
|
|
; CHECK-NEXT: shufflevector
|
|
|
|
; CHECK-NEXT: ret
|
|
|
|
}
|
|
|
|
|
2010-07-12 01:19:22 +00:00
|
|
|
; PR7311 - Don't create invalid IR on scalar->vector cast.
|
|
|
|
define <2 x float> @test63(i64 %tmp8) nounwind {
|
|
|
|
entry:
|
|
|
|
%a = bitcast i64 %tmp8 to <2 x i32>
|
|
|
|
%vcvt.i = uitofp <2 x i32> %a to <2 x float>
|
|
|
|
ret <2 x float> %vcvt.i
|
|
|
|
; CHECK: @test63
|
|
|
|
; CHECK: bitcast
|
|
|
|
; CHECK: uitofp
|
|
|
|
}
|
|
|
|
|