Why is llvm.loop.unroll.disable appended for -O1 -emit-llvm

Hi all,

My guess to this question is that the logic is the same that -O0 will append the optnone. However I have no foundation on my guess. Does anyone know the heuristic behind this? Moreover, is there other tags appended just like llvm.loop.unroll.disable, and is there a place where logics are gathered (or I should just simply trace into every detail within PassBuilderPipelines.cpp)?

Thank you for reading my question.


eop Chen

Running clang with -mllvm --print-changed=quiet -mllvm --print-module-scope and grepping for llvm.loop.unroll.disable should show which pass adds llvm.loop.unroll.disable.

Searching “llvm.loop.unroll.disable” in LLVM shows Loop::setLoopAlreadyUnrolled() which is probably where that gets added. The various unroll passes will set the metadata once they’ve done some sort of unrolling/peeling so that another pass in the future won’t do it again.

Hi @aeubanks,

Thank you for dropping by and replying.

I tried the commands and also find --print-changed=diff helpful and less verbose. However at the very first dump, *** IR Dump At Start ***, of clang -O1 -emit-llvm -mllvm --print-changed=diff -mllvm -print-module-scope, I see llvm.loop.unroll.disable already appended into the loop.

Further more I tried to set a breakpoint on the places from greping llvm.loop.unroll.disable.

grep -r "llvm.loop.unroll.disable" llvm/lib
llvm/lib/Analysis/LoopInfo.cpp:      MDNode::get(Context, MDString::get(Context, "llvm.loop.unroll.disable"));
llvm/lib/Analysis/LoopInfo.cpp:  // llvm.loop.unroll.disable and llvm.loop.isvectorized.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:            S && S->getString().startswith("llvm.loop.unroll.disable");
llvm/lib/Transforms/Utils/LoopUtils.cpp:  if (getBooleanLoopAttribute(L, "llvm.loop.unroll.disable"))
llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp:      Context, {MDString::get(Context, "llvm.loop.unroll.disable")});
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp:// llvm.loop.unroll.disable.
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp:  // llvm.loop.unroll.disable is marked on the back edges of a loop. Therefore,
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp:  // whether its metadata contains llvm.loop.unroll.disable.
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp:        if (GetUnrollMetadata(LoopID, "llvm.loop.unroll.disable"))

Nothing was stopped with breakpoint set at the following.

(gdb) info b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x00000000083e6da7 in llvm::Loop::setLoopAlreadyUnrolled()
2       breakpoint     keep y   0x00000000097f5272 in DisableAllLoopOptsOnLoop(llvm::Loop&)

I currently still can’t find where the insertion happens. Do you reproduce the same result as me?

Thanks again for replying.


eop Chen