<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/77517>77517</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            IR Language Reference for `is.constant.*` is potentially unclear
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          NCGThompson
      </td>
    </tr>
</table>

<pre>
    The entry for `@llvm.is.constant.*` has this sentence:

https://github.com/llvm/llvm-project/blob/1b8e39a1a2e8237852914501e3361d98af6db054/llvm/docs/LangRef.rst?plain=1#L27223C1-L27224
> On the other hand, if constant folding is not run, it will never evaluate to true, even in simple cases.

It comes after a paragraph talking on the case when the intrinsic's operand is an inline-able function's operand. It's unclear if the sentence is a continuation of the previous paragraph or if it is talking about the intrinsic overall. The later interpretation is incorrect in the simplest case:
```llvm
%2 = call i1 @llvm.is.constant.i1(i1 false) ;Always evaluates to true
```
While this case is useless, it can still occur because the IR is procedurally generated.

The former interpretation is arguably incorrect as well. If a function has the `alwaysinline` attribute, the function call has a literal as an operand, the function contains an `is.constant` intrinsic that directly reads the function's input, and optimizations are set to `-O0`, then the intrinsic will be folded to true during the `always-inline` pass.

[Compiler Explorer link](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,selection:(endColumn:1,endLineNumber:17,positionColumn:1,positionLineNumber:17,selectionStartColumn:1,selectionStartLineNumber:17,startColumn:1,startLineNumber:17),source:'define+i1+@constant_literal(i1+noundef+%250)+local_unnamed_addr+%230+%7B%0A++++%252+%3D+call+i1+@llvm.is.constant.i1(i1+false)%0A++++%253+%3D+xor+i1+%252,+true%0A++++ret+i1+%253%0A%7D%0A%0Adefine+i1+@outer_inline(i1+noundef+%250)+unnamed_addr+%7B%0A++++%252+%3D+call+i1+@is_const(i1+zeroext+false)%0A++++%253+%3D+xor+i1+%252,+true%0A++++ret+i1+%253%0A%7D%0A%0Adefine+zeroext+i1+@is_const(i1+zeroext+%250)+unnamed_addr+alwaysinline+%7B%0A++++%252+%3D+call+i1+@llvm.is.constant.i1(i1+%250)%0A++++ret+i1+%252%0A%7D%0A%0Adeclare+i1+@llvm.is.constant.i1(i1+%25operand)+nounwind+readnone'),l:'5',n:'0',o:'LLVM+IR+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:irclangtrunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:llvm,libs:!(),options:'-O0',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+clang+(trunk)+(Editor+%231)',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV19v47gR_zT0CxFDoizLevBD7GyKAOmlyF2vj8FIHNm8pUiBpJz4Pn0xlOxYiW_39tAWBQLHJOfvb34zNMF7tTOIa5ZvWH43gz7srVv_tP3bL3vbdt6aWWXlcf3LHjma4I68sY6zZcIWidaHdq78vLbGBzBhzsQtWyZ8D56HvfLcowloamTZLUvuWDJ-7kPoPO2Jeybudyrs-2pe25aJezI5_rvpnP0N68DEfaVtxcR9Wq0wKyEFgSuRFatclOkiT1LMsmUqyxU0S1kl-eLdjrS1Z-L-EczuGZu584Fl950GZVh2lzKRPYpCiGyb3sQvizHK7At_MjzskduwR8f3YCQTW64afsqVN1ZLZXZceW5s4K43USLwV6U1N3hAx_EAuoeAPFgeXI8kgQc0XBnuVdtp5DV49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