Skip to content

Commit 653b79d

Browse files
authored
llvm2alive: respect range attributes on the return value of an intrinsic call (#1097)
1 parent 338f681 commit 653b79d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

llvm_util/llvm2alive.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,12 @@ class llvm2alive_ : public llvm::InstVisitor<llvm2alive_, unique_ptr<Instr>> {
12251225
if (ret) {
12261226
FnAttrs attrs;
12271227
parse_fn_attrs(i, attrs);
1228+
if (i.hasRetAttr(llvm::Attribute::Range)) {
1229+
auto &ptr = *ret;
1230+
BB->addInstr(std::move(ret));
1231+
ret =
1232+
handleRangeAttrNoInsert(i.getRetAttr(llvm::Attribute::Range), ptr);
1233+
}
12281234
add_identifier(i, *ret.get());
12291235
if (attrs.has(FnAttrs::NoUndef)) {
12301236
auto &ptr = *ret;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; ERROR: Target is more poisonous than source
2+
3+
define i1 @src(i32 %x) {
4+
entry:
5+
%cmp1 = icmp ne i32 %x, 0
6+
%popcnt = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)
7+
%cmp2 = icmp ult i32 %popcnt, 2
8+
%sel = select i1 %cmp1, i1 %cmp2, i1 false
9+
ret i1 %sel
10+
}
11+
12+
define i1 @tgt(i32 %x) {
13+
entry:
14+
%popcnt = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)
15+
%sel = icmp eq i32 %popcnt, 1
16+
ret i1 %sel
17+
}

0 commit comments

Comments
 (0)