2016-04-20 01:51:52 +02:00
|
|
|
; RUN: llc -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s
|
2013-01-31 13:12:40 +01:00
|
|
|
|
|
|
|
; First, a simple example from Clang. The registers could plausibly be
|
|
|
|
; different, but probably won't be.
|
|
|
|
|
|
|
|
%struct.foo = type { i8, [2 x i8], i8 }
|
|
|
|
|
|
|
|
define [1 x i64] @from_clang([1 x i64] %f.coerce, i32 %n) nounwind readnone {
|
2013-07-14 08:24:09 +02:00
|
|
|
; CHECK-LABEL: from_clang:
|
2014-05-01 14:29:38 +02:00
|
|
|
; CHECK: bfi {{w[0-9]+}}, {{w[0-9]+}}, #3, #4
|
2013-01-31 13:12:40 +01:00
|
|
|
|
|
|
|
entry:
|
|
|
|
%f.coerce.fca.0.extract = extractvalue [1 x i64] %f.coerce, 0
|
|
|
|
%tmp.sroa.0.0.extract.trunc = trunc i64 %f.coerce.fca.0.extract to i32
|
|
|
|
%bf.value = shl i32 %n, 3
|
|
|
|
%0 = and i32 %bf.value, 120
|
|
|
|
%f.sroa.0.0.insert.ext.masked = and i32 %tmp.sroa.0.0.extract.trunc, 135
|
|
|
|
%1 = or i32 %f.sroa.0.0.insert.ext.masked, %0
|
|
|
|
%f.sroa.0.0.extract.trunc = zext i32 %1 to i64
|
|
|
|
%tmp1.sroa.1.1.insert.insert = and i64 %f.coerce.fca.0.extract, 4294967040
|
|
|
|
%tmp1.sroa.0.0.insert.insert = or i64 %f.sroa.0.0.extract.trunc, %tmp1.sroa.1.1.insert.insert
|
|
|
|
%.fca.0.insert = insertvalue [1 x i64] undef, i64 %tmp1.sroa.0.0.insert.insert, 0
|
|
|
|
ret [1 x i64] %.fca.0.insert
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test_whole32(i32* %existing, i32* %new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_whole32:
|
2014-04-24 14:11:53 +02:00
|
|
|
|
2014-05-01 14:29:38 +02:00
|
|
|
; CHECK: bfi {{w[0-9]+}}, {{w[0-9]+}}, #26, #5
|
2013-01-31 13:12:40 +01:00
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i32, i32* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i32 %oldval, 2214592511 ; =0x83ffffff
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i32, i32* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i32 %newval, 26
|
|
|
|
%newval_masked = and i32 %newval_shifted, 2080374784 ; = 0x7c000000
|
|
|
|
|
|
|
|
%combined = or i32 %oldval_keep, %newval_masked
|
|
|
|
store volatile i32 %combined, i32* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test_whole64(i64* %existing, i64* %new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_whole64:
|
2014-05-01 14:29:38 +02:00
|
|
|
; CHECK: bfi {{x[0-9]+}}, {{x[0-9]+}}, #26, #14
|
2013-01-31 13:12:40 +01:00
|
|
|
; CHECK-NOT: and
|
|
|
|
; CHECK: ret
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i64, i64* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i64 %oldval, 18446742974265032703 ; = 0xffffff0003ffffffL
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i64, i64* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i64 %newval, 26
|
|
|
|
%newval_masked = and i64 %newval_shifted, 1099444518912 ; = 0xfffc000000
|
|
|
|
|
|
|
|
%combined = or i64 %oldval_keep, %newval_masked
|
|
|
|
store volatile i64 %combined, i64* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test_whole32_from64(i64* %existing, i64* %new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_whole32_from64:
|
2014-04-24 14:11:53 +02:00
|
|
|
|
2014-05-01 14:29:38 +02:00
|
|
|
|
2014-05-24 14:50:23 +02:00
|
|
|
; CHECK: bfxil {{x[0-9]+}}, {{x[0-9]+}}, #0, #16
|
2014-04-24 14:11:53 +02:00
|
|
|
|
2013-01-31 13:12:40 +01:00
|
|
|
; CHECK: ret
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i64, i64* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i64 %oldval, 4294901760 ; = 0xffff0000
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i64, i64* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_masked = and i64 %newval, 65535 ; = 0xffff
|
|
|
|
|
|
|
|
%combined = or i64 %oldval_keep, %newval_masked
|
|
|
|
store volatile i64 %combined, i64* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test_32bit_masked(i32 *%existing, i32 *%new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_32bit_masked:
|
2014-04-24 14:11:53 +02:00
|
|
|
|
2014-05-24 14:50:23 +02:00
|
|
|
; CHECK: and
|
2014-05-01 14:29:38 +02:00
|
|
|
; CHECK: bfi [[INSERT:w[0-9]+]], {{w[0-9]+}}, #3, #4
|
2013-01-31 13:12:40 +01:00
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i32, i32* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i32 %oldval, 135 ; = 0x87
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i32, i32* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i32 %newval, 3
|
|
|
|
%newval_masked = and i32 %newval_shifted, 120 ; = 0x78
|
|
|
|
|
|
|
|
%combined = or i32 %oldval_keep, %newval_masked
|
|
|
|
store volatile i32 %combined, i32* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @test_64bit_masked(i64 *%existing, i64 *%new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_64bit_masked:
|
2014-05-24 14:50:23 +02:00
|
|
|
; CHECK: and
|
2014-05-01 14:29:38 +02:00
|
|
|
; CHECK: bfi [[INSERT:x[0-9]+]], {{x[0-9]+}}, #40, #8
|
2013-01-31 13:12:40 +01:00
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i64, i64* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i64 %oldval, 1095216660480 ; = 0xff_0000_0000
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i64, i64* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i64 %newval, 40
|
|
|
|
%newval_masked = and i64 %newval_shifted, 280375465082880 ; = 0xff00_0000_0000
|
|
|
|
|
|
|
|
%combined = or i64 %newval_masked, %oldval_keep
|
|
|
|
store volatile i64 %combined, i64* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Mask is too complicated for literal ANDwwi, make sure other avenues are tried.
|
|
|
|
define void @test_32bit_complexmask(i32 *%existing, i32 *%new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_32bit_complexmask:
|
2014-04-24 14:11:53 +02:00
|
|
|
|
2014-05-24 14:50:23 +02:00
|
|
|
; CHECK: and
|
2014-05-01 14:29:38 +02:00
|
|
|
; CHECK: bfi {{w[0-9]+}}, {{w[0-9]+}}, #3, #4
|
2013-01-31 13:12:40 +01:00
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i32, i32* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i32 %oldval, 647 ; = 0x287
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i32, i32* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i32 %newval, 3
|
|
|
|
%newval_masked = and i32 %newval_shifted, 120 ; = 0x278
|
|
|
|
|
|
|
|
%combined = or i32 %oldval_keep, %newval_masked
|
|
|
|
store volatile i32 %combined, i32* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Neither mask is is a contiguous set of 1s. BFI can't be used
|
|
|
|
define void @test_32bit_badmask(i32 *%existing, i32 *%new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_32bit_badmask:
|
2013-01-31 13:12:40 +01:00
|
|
|
; CHECK-NOT: bfi
|
2014-04-24 14:11:53 +02:00
|
|
|
; CHECK-NOT: bfm
|
2013-01-31 13:12:40 +01:00
|
|
|
; CHECK: ret
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i32, i32* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i32 %oldval, 135 ; = 0x87
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i32, i32* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i32 %newval, 3
|
|
|
|
%newval_masked = and i32 %newval_shifted, 632 ; = 0x278
|
|
|
|
|
|
|
|
%combined = or i32 %oldval_keep, %newval_masked
|
|
|
|
store volatile i32 %combined, i32* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Ditto
|
|
|
|
define void @test_64bit_badmask(i64 *%existing, i64 *%new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_64bit_badmask:
|
2013-01-31 13:12:40 +01:00
|
|
|
; CHECK-NOT: bfi
|
2014-04-24 14:11:53 +02:00
|
|
|
; CHECK-NOT: bfm
|
2013-01-31 13:12:40 +01:00
|
|
|
; CHECK: ret
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i64, i64* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i64 %oldval, 135 ; = 0x87
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load volatile i64, i64* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i64 %newval, 3
|
|
|
|
%newval_masked = and i64 %newval_shifted, 664 ; = 0x278
|
|
|
|
|
|
|
|
%combined = or i64 %oldval_keep, %newval_masked
|
|
|
|
store volatile i64 %combined, i64* %existing
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Bitfield insert where there's a left-over shr needed at the beginning
|
|
|
|
; (e.g. result of str.bf1 = str.bf2)
|
|
|
|
define void @test_32bit_with_shr(i32* %existing, i32* %new) {
|
2013-07-13 22:38:47 +02:00
|
|
|
; CHECK-LABEL: test_32bit_with_shr:
|
2013-01-31 13:12:40 +01:00
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%oldval = load volatile i32, i32* %existing
|
2013-01-31 13:12:40 +01:00
|
|
|
%oldval_keep = and i32 %oldval, 2214592511 ; =0x83ffffff
|
|
|
|
|
2015-02-27 22:17:42 +01:00
|
|
|
%newval = load i32, i32* %new
|
2013-01-31 13:12:40 +01:00
|
|
|
%newval_shifted = shl i32 %newval, 12
|
|
|
|
%newval_masked = and i32 %newval_shifted, 2080374784 ; = 0x7c000000
|
|
|
|
|
|
|
|
%combined = or i32 %oldval_keep, %newval_masked
|
|
|
|
store volatile i32 %combined, i32* %existing
|
|
|
|
; CHECK: lsr [[BIT:w[0-9]+]], {{w[0-9]+}}, #14
|
2014-05-01 14:29:38 +02:00
|
|
|
; CHECK: bfi {{w[0-9]+}}, [[BIT]], #26, #5
|
2013-01-31 13:12:40 +01:00
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
2015-09-18 19:11:53 +02:00
|
|
|
|
|
|
|
; Bitfield insert where the second or operand is a better match to be folded into the BFM
|
|
|
|
define void @test_32bit_opnd1_better(i32* %existing, i32* %new) {
|
|
|
|
; CHECK-LABEL: test_32bit_opnd1_better:
|
|
|
|
|
|
|
|
%oldval = load volatile i32, i32* %existing
|
|
|
|
%oldval_keep = and i32 %oldval, 65535 ; 0x0000ffff
|
|
|
|
|
|
|
|
%newval = load i32, i32* %new
|
|
|
|
%newval_shifted = shl i32 %newval, 16
|
|
|
|
%newval_masked = and i32 %newval_shifted, 16711680 ; 0x00ff0000
|
|
|
|
|
|
|
|
%combined = or i32 %oldval_keep, %newval_masked
|
|
|
|
store volatile i32 %combined, i32* %existing
|
|
|
|
; CHECK: and [[BIT:w[0-9]+]], {{w[0-9]+}}, #0xffff
|
|
|
|
; CHECK: bfi [[BIT]], {{w[0-9]+}}, #16, #8
|
|
|
|
|
|
|
|
ret void
|
|
|
|
}
|
2015-12-01 20:17:49 +01:00
|
|
|
|
|
|
|
; Tests when all the bits from one operand are not useful
|
|
|
|
define i32 @test_nouseful_bits(i8 %a, i32 %b) {
|
|
|
|
; CHECK-LABEL: test_nouseful_bits:
|
|
|
|
; CHECK: bfi
|
|
|
|
; CHECK: bfi
|
|
|
|
; CHECK: bfi
|
|
|
|
; CHECK-NOT: bfi
|
|
|
|
; CHECK-NOT: or
|
|
|
|
; CHECK: lsl
|
|
|
|
%conv = zext i8 %a to i32 ; 0 0 0 A
|
|
|
|
%shl = shl i32 %b, 8 ; B2 B1 B0 0
|
|
|
|
%or = or i32 %conv, %shl ; B2 B1 B0 A
|
|
|
|
%shl.1 = shl i32 %or, 8 ; B1 B0 A 0
|
|
|
|
%or.1 = or i32 %conv, %shl.1 ; B1 B0 A A
|
|
|
|
%shl.2 = shl i32 %or.1, 8 ; B0 A A 0
|
|
|
|
%or.2 = or i32 %conv, %shl.2 ; B0 A A A
|
|
|
|
%shl.3 = shl i32 %or.2, 8 ; A A A 0
|
|
|
|
%or.3 = or i32 %conv, %shl.3 ; A A A A
|
|
|
|
%shl.4 = shl i32 %or.3, 8 ; A A A 0
|
|
|
|
ret i32 %shl.4
|
|
|
|
}
|