[LLVMdev] Adding an intrinsic that requires a constant parameter

Justin Holewinski justin.holewinski at gmail.com
Thu May 1 05:10:22 PDT 2014


My understanding of intrinsics in LLVM is that an optimization pass cannot
touch an intrinsic unless it (1) is specifically programmed to have
knowledge of the intrinsic, or (2) uses only declared properties of the
intrinsic, like IntrNoMem.  So, for example, a pass may move an unknown
intrinsic around memory ops if its defined IntrNoMem, but it cannot hoist
constants for arbitrary intrinsics.  Is this correct?  I can't find this
codified anywhere in the documentation.

The context for this question is adding an intrinsic that requires a
constant parameter.  There is no way to define this property in the
tablegen description currently.  I want to verify that if I add such an
intrinsic, it would be illegal for any existing optimization pass to hoist
the constant parameter.  For example, if I add a target intrinsic llvm.foo
that takes two parameters: i32 and i1, where the i1 parameter must be a
constant (same as llvm.cttz), I want to verify that the following
optimization is illegal without having to change any LLVM passes:

Input:

define i32 @f0(i32 %a, i1 %pred) {
  br i1 %pred, label %first, label %second
first:
  %r0 = tail call i32 @llvm.foo.i32(i32 %a, i1 true)
  br label %end
second:
  %r1 = tail call i32 @llvm.foo.i32(i32 %a, i1 false)
  br label %end
end:
  %r = phi i32 [%r0, %first], [%r1, %second]
  ret i32 %r
}

Output:

define i32 @f1(i32 %a, i1 %pred) {
  %r = tail call i32 @llvm.foo.i32(i32 %a, i1 %pred)
  ret i32 %r
}

-- 

Thanks,

Justin Holewinski
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140501/16e5fbee/attachment.html>


More information about the llvm-dev mailing list