Skip to content

Instantly share code, notes, and snippets.

@christianparpart
Created September 22, 2010 12:13
Show Gist options
  • Save christianparpart/591569 to your computer and use it in GitHub Desktop.
Save christianparpart/591569 to your computer and use it in GitHub Desktop.
llvm::Value *Runner::emitToLower(llvm::Value *value)
{
#if 1 == 0 // {{{ C equivalent
return value >= 'A' && value <= 'Z'
? value + 32
: value;
#endif // }}}
// IR:
// %off = add %ch, -65
// %lwr = add %ch, 32
// %cnd = icmp ult %off, 26
// %result = select %cnd, %off, %lwr
llvm::Value *offset = builder_.CreateAdd(value, llvm::ConstantInt::get(value->getType(), -65));
llvm::Value *lwr = builder_.CreateAdd(value, llvm::ConstantInt::get(value->getType(), 32));
llvm::Value *cnd = builder_.CreateICmpULT(offset, llvm::ConstantInt::get(value->getType(), 26));
llvm::Value *result = builder_.CreateSelect(cnd, offset, lwr);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment