add support for align assume op bundle with the extra param
MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
@@ -29,6 +29,7 @@ namespace {
unsigned constexpr_idx;
unsigned copy_idx;
+unsigned alignopbundle_idx;
#if 0
string_view s(llvm::StringRef str) {
@@ -712,14 +713,22 @@ public:
} else if (name == "align") {
llvm::Value *ptr = bundle.Inputs[0].get();
llvm::Value *align = bundle.Inputs[1].get();
- if (bundle.Inputs.size() != 2)
- // TODO: "align" assume operand bundle may take a third argument.
- return error(i);
-
auto *aptr = get_operand(ptr), *aalign = get_operand(align);
- if (!aptr || !aalign)
+ if (!aptr || !aalign || align->getType()->getIntegerBitWidth() > 64)
return error(i);
+ if (bundle.Inputs.size() >= 3) {
+ assert(bundle.Inputs.size() == 3);
+ auto gep = make_unique<GEP>(
+ aptr->getType(),
+ "#align_adjustedptr" + to_string(alignopbundle_idx++),
+ *aptr, false);
+ gep->addIdx(-1ull, *get_operand(bundle.Inputs[2].get()));
+
+ aptr = gep.get();
+ BB->addInstr(move(gep));
+ }
+
vector<Value *> args = {aptr, aalign};
BB->addInstr(make_unique<Assume>(move(args), Assume::Align));
} else if (name == "nonnull") {
@@ -1215,6 +1224,7 @@ public:
optional<Function> run() {
constexpr_idx = 0;
copy_idx = 0;
+ alignopbundle_idx = 0;
// don't even bother if number of BBs or instructions is huge..
if (distance(f.begin(), f.end()) > 5000 ||

RENAME
tests/alive-tv/assume/align-op3.srctgt.ll
tests/alive-tv/assume/align-extraop.srctgt.ll
-; SKIP-IDENTITY
declare void @llvm.assume(i1)
declare void @f(i8* align(4)) ; has no noundef
@@ -14,5 +13,4 @@ define void @tgt(i8* %ptr) {
ret void
}
-; align with 3 ops isn't supported yet.
-; XFAIL: Unsupported instruction
+; ERROR: Source is more defined than target

ADD
tests/alive-tv/assume/align-extraop2.srctgt.ll
+declare void @llvm.assume(i1)
+
+declare void @f(i8* align(4) noundef)
+
+define void @src(i8* %ptr) {
+ call void @f(i8* %ptr)
+ ret void
+}
+
+define void @tgt(i8* %ptr) {
+ call void @f(i8* %ptr)
+ %ptr2 = getelementptr i8, i8* %ptr, i64 1
+ call void @llvm.assume(i1 1) [ "align"(i8* %ptr2, i64 4, i64 1) ]
+ ret void
+}

ADD
tests/alive-tv/assume/align-extraop3.srctgt.ll
+declare void @llvm.assume(i1)
+
+declare void @f(i8* align(4) noundef)
+
+define void @src(i8* %ptr) {
+ call void @f(i8* %ptr)
+ ret void
+}
+
+define void @tgt(i8* %ptr) {
+ call void @f(i8* %ptr)
+ %ptr2 = getelementptr i8, i8* %ptr, i64 1
+ call void @llvm.assume(i1 1) [ "align"(i8* %ptr2, i64 4, i64 2) ] ; UB
+ ret void
+}
+
+; ERROR: Source is more defined than target

ADD
tests/alive-tv/assume/align-extraop4.srctgt.ll
+; SKIP-IDENTITY
+declare void @llvm.assume(i1)
+
+declare void @f(i8* align(4) noundef)
+
+define void @src(i8* %ptr) {
+ call void @f(i8* %ptr)
+ ret void
+}
+
+define void @tgt(i8* %ptr) {
+ call void @f(i8* %ptr)
+ %ptr2 = getelementptr i8, i8* %ptr, i64 1
+ call void @llvm.assume(i1 1) [ "align"(i8* %ptr2, i128 4, i128 2) ] ; UB
+ ret void
+}
+
+; Check that this does not crash
+; ERROR: Unsupported instruction

add support for align assume op bundle with the extra param (#694)