-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/fix more intrinsics: smin, smax, trap, bswap, popcnt, ctlz, and c…
…ttz (#188) add / fix support for some intrisics which either weren't implemented at all (smin, smax, and trap), or weren't actually working (bswap, popcnt, ctlz, and cttz).
- Loading branch information
Showing
6 changed files
with
210 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
declare i64 @llvm.ctpop.i64(i64) | ||
declare i64 @llvm.ctlz.i64(i64, i1) ; i1: is_zero_poison | ||
declare i16 @llvm.ctlz.i16(i16, i1) ; i1: is_zero_poison | ||
declare i64 @llvm.cttz.i64(i64, i1); i1: is_zero_poison> | ||
declare i16 @llvm.cttz.i16(i16, i1); i1: is_zero_poison> | ||
|
||
|
||
define dso_local i32 @main() #0 { | ||
ctpop.1: | ||
%ctpop.1.val = call i64 @llvm.ctpop.i64(i64 18446744073709551615) ; 0xffffffffffffffff | ||
%ctpop.1.ok = icmp eq i64 %ctpop.1.val, 64 | ||
br i1 %ctpop.1.ok, label %ctpop.2, label %error | ||
|
||
ctpop.2: | ||
%ctpop.2.val = call i64 @llvm.ctpop.i64(i64 0) | ||
%ctpop.2.ok = icmp eq i64 %ctpop.2.val, 0 | ||
br i1 %ctpop.2.ok, label %ctpop.3, label %error | ||
|
||
ctpop.3: | ||
%ctpop.3.val = call i64 @llvm.ctpop.i64(i64 181) ; 0b10110101 | ||
%ctpop.3.ok = icmp eq i64 %ctpop.3.val, 5 | ||
br i1 %ctpop.3.ok, label %ctlz.1, label %error | ||
|
||
ctlz.1: | ||
%ctlz.1.val = call i64 @llvm.ctlz.i64(i64 18446744073709551615, i1 0) ; 0xffffffffffffffff | ||
%ctlz.1.ok = icmp eq i64 %ctlz.1.val, 0 | ||
br i1 %ctlz.1.ok, label %ctlz.2, label %error | ||
|
||
ctlz.2: | ||
%ctlz.2.val = call i64 @llvm.ctlz.i64(i64 1, i1 0) | ||
%ctlz.2.ok = icmp eq i64 %ctlz.2.val, 63 | ||
br i1 %ctlz.2.ok, label %ctlz.3, label %error | ||
|
||
ctlz.3: | ||
%ctlz.3.val = call i16 @llvm.ctlz.i16(i16 181, i1 0) ; 0b10110101 | ||
%ctlz.3.ok = icmp eq i16 %ctlz.3.val, 8 | ||
br i1 %ctlz.3.ok, label %cttz.1, label %error | ||
|
||
cttz.1: | ||
%cttz.1.val = call i64 @llvm.cttz.i64(i64 18446744073709551615, i1 0) ; 0xffffffffffffffff | ||
%cttz.1.ok = icmp eq i64 %cttz.1.val, 0 | ||
br i1 %cttz.1.ok, label %cttz.2, label %error | ||
|
||
cttz.2: | ||
%cttz.2.val = call i64 @llvm.cttz.i64(i64 1, i1 0) | ||
%cttz.2.ok = icmp eq i64 %cttz.2.val, 0 | ||
br i1 %cttz.2.ok, label %cttz.3, label %error | ||
|
||
cttz.3: | ||
%cttz.3.val = call i16 @llvm.cttz.i16(i16 180, i1 0) ; 0b10110100 | ||
%cttz.3.ok = icmp eq i16 %cttz.3.val, 2 | ||
br i1 %cttz.3.ok, label %ok, label %error | ||
|
||
ok: | ||
ret i32 6 | ||
|
||
error: | ||
%retVal = phi i32 | ||
[ 20, %ctpop.1 ], | ||
[ 21, %ctpop.2 ], | ||
[ 22, %ctpop.3 ], | ||
[ 23, %ctlz.1 ], | ||
[ 24, %ctlz.2 ], | ||
[ 25, %ctlz.3 ], | ||
[ 26, %cttz.1 ], | ||
[ 27, %cttz.2 ], | ||
[ 28, %cttz.3 ] | ||
ret i32 %retVal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
declare i16 @llvm.bswap.i16(i16) | ||
declare i32 @llvm.bswap.i32(i32) | ||
declare i64 @llvm.bswap.i64(i64) | ||
|
||
define dso_local i32 @main() #0 { | ||
bswap.i16: | ||
%bswap.i16.val = call i16 @llvm.bswap.i16(i16 4660) ; 0x1234 | ||
%bswap.i16.ok = icmp eq i16 %bswap.i16.val, 13330 ; 0x3412 | ||
br i1 %bswap.i16.ok, label %bswap.i32, label %error | ||
|
||
bswap.i32: | ||
%bswap.i32.val = call i32 @llvm.bswap.i32(i32 305419896) ; 0x12345678 | ||
%bswap.i32.ok = icmp eq i32 %bswap.i32.val, 2018915346 ; 0x78563412 | ||
br i1 %bswap.i32.ok, label %bswap.i64, label %error | ||
|
||
bswap.i64: | ||
%bswap.i64.val = call i64 @llvm.bswap.i64(i64 1311768467463790320) ; 0x123456789abcdef0 | ||
%bswap.i64.ok = icmp eq i64 %bswap.i64.val, 17356517385562371090 ; 0xf0debc9a78563412 | ||
br i1 %bswap.i64.ok, label %ok, label %error | ||
|
||
ok: | ||
ret i32 6 | ||
|
||
error: | ||
%retVal = phi i32 | ||
[ 20, %bswap.i16 ], | ||
[ 21, %bswap.i32 ], | ||
[ 22, %bswap.i64 ] | ||
ret i32 %retVal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
declare i64 @llvm.smin.i64(i64, i64) | ||
declare i64 @llvm.smax.i64(i64, i64) | ||
declare i64 @llvm.umin.i64(i64, i64) | ||
declare i64 @llvm.umax.i64(i64, i64) | ||
|
||
define dso_local i32 @main() #0 { | ||
smin.check: | ||
%smin.res = call i64 @llvm.smin.i64(i64 6, i64 -6) | ||
%smin.ok = icmp eq i64 %smin.res, -6 | ||
br i1 %smin.ok, label %smax.check, label %error | ||
|
||
smax.check: | ||
%smax.res = call i64 @llvm.smax.i64(i64 6, i64 -6) | ||
%smax.ok = icmp eq i64 %smax.res, 6 | ||
br i1 %smax.ok, label %umin.check, label %error | ||
|
||
umin.check: | ||
%umin.res = call i64 @llvm.umin.i64(i64 6, i64 -6) | ||
%umin.ok = icmp eq i64 %umin.res, 6 | ||
br i1 %umin.ok, label %umax.check, label %error | ||
|
||
umax.check: | ||
%umax.res = call i64 @llvm.umax.i64(i64 6, i64 -6) | ||
%umax.ok = icmp eq i64 %umax.res, -6 | ||
br i1 %umax.ok, label %ok, label %error | ||
|
||
|
||
ok: | ||
ret i32 6 | ||
|
||
error: | ||
%retVal = phi i32 | ||
[ 20, %smin.check ], | ||
[ 21, %smax.check ], | ||
[ 22, %umin.check ], | ||
[ 23, %umax.check ] | ||
ret i32 %retVal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
declare void @llvm.trap() cold noreturn nounwind | ||
|
||
define dso_local i32 @main() #0 { | ||
ret i32 6 | ||
} | ||
|
||
define dso_local void @this_should_not_happen() { | ||
call void @llvm.trap() | ||
unreachable | ||
} |