1; bswap should be constant folded when it is passed a constant argument 2 3; RUN: llc < %s -march=x86 -mcpu=i686 | FileCheck %s 4 5declare i16 @llvm.bswap.i16(i16) 6 7declare i32 @llvm.bswap.i32(i32) 8 9declare i64 @llvm.bswap.i64(i64) 10 11define i16 @W(i16 %A) { 12; CHECK: W: 13; CHECK: rolw $8, %ax 14 %Z = call i16 @llvm.bswap.i16( i16 %A ) ; <i16> [#uses=1] 15 ret i16 %Z 16} 17 18define i32 @X(i32 %A) { 19; CHECK: X: 20; CHECK: bswapl %eax 21 %Z = call i32 @llvm.bswap.i32( i32 %A ) ; <i32> [#uses=1] 22 ret i32 %Z 23} 24 25define i64 @Y(i64 %A) { 26; CHECK: Y: 27; CHECK: bswapl %eax 28; CHECK: bswapl %edx 29 %Z = call i64 @llvm.bswap.i64( i64 %A ) ; <i64> [#uses=1] 30 ret i64 %Z 31} 32 33; rdar://9164521 34define i32 @test1(i32 %a) nounwind readnone { 35entry: 36; CHECK: test1 37; CHECK: bswapl %eax 38; CHECK: shrl $16, %eax 39 %and = lshr i32 %a, 8 40 %shr3 = and i32 %and, 255 41 %and2 = shl i32 %a, 8 42 %shl = and i32 %and2, 65280 43 %or = or i32 %shr3, %shl 44 ret i32 %or 45} 46 47define i32 @test2(i32 %a) nounwind readnone { 48entry: 49; CHECK: test2 50; CHECK: bswapl %eax 51; CHECK: sarl $16, %eax 52 %and = lshr i32 %a, 8 53 %shr4 = and i32 %and, 255 54 %and2 = shl i32 %a, 8 55 %or = or i32 %shr4, %and2 56 %sext = shl i32 %or, 16 57 %conv3 = ashr exact i32 %sext, 16 58 ret i32 %conv3 59} 60