Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify llvm: IteNode::init(): Must take either two logical nodes or two bv nodes as 'then' and 'else' branches. #1358

Open
KarlVogel opened this issue Aug 29, 2024 · 0 comments

Comments

@KarlVogel
Copy link

Using simplify with LLVM-14 seems to run into some issues in some cases. Had a simplify fail with "IteNode::init(): Must take either two logical nodes or two bv nodes as 'then' and 'else' branches.".

Reduced the LLVM asm code that was produced by simplify to following code that still triggers it:
(code is non sensical, since I removed most that didn't matter)

define i32 @__triton(i8 %SymVar_4, i32 %SymVar_7) local_unnamed_addr #0 {
entry:
  %0 = and i8 %SymVar_4, 63
  %1 = xor i8 %0, 3
  %2 = zext i32 %SymVar_7 to i64
  %3 = and i64 %2, 2048
  %4 = icmp ne i64 %3, 0
  %5 = icmp ne i8 %1, 1
  %6 = select i1 %5, i1 %4, i1 false
  %7 = zext i1 %6 to i32
  ret i32 %7
}

It fails on the '%6' line, operand(1) has isLogical() true, while operand(2) false.

Test cpp program to trigger it:

#include <iostream>
#include <triton/context.hpp>
#include <triton/llvmToTriton.hpp>
#include <triton/x86Specifications.hpp>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/SourceMgr.h>
#include <llvm/IRReader/IRReader.h>
#include <llvm/ADT/StringRef.h>

using namespace triton;

int main(int ac, const char **av) {
  triton::Context ctx;
  llvm::SMDiagnostic Err;
  llvm::LLVMContext Context;

  if (ac != 2) {
    std::cerr << "Usage: " << av[0] << " <file>\n";
    return 1;
  }
  ctx.setArchitecture(triton::arch::ARCH_X86_64);
  std::unique_ptr<llvm::Module> M = llvm::parseIRFile(llvm::StringRef(av[1]), Err, Context);
  if (!M) {
    std::cerr << "Failed to parse input file:" << Err.getMessage().str() << std::endl;
    return 1;
  }
  llvm::Function* function = M->getFunction("__triton");
  llvm::BasicBlock& entryBlock = function->getEntryBlock();
  llvm::Instruction* returnInstruction = entryBlock.getTerminator();
  triton::ast::LLVMToTriton lvmtt(ctx);
  lvmtt.convert(M.get());
  return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant