This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAGBuilder] drop special handling for CallBr
AbandonedPublic

Authored by nickdesaulniers on Dec 8 2021, 4:52 PM.

Details

Summary

Now that indirect destinations are using "i" constraints rather than "X"
we no longer need this special handling.

Add a test case that was previously ICE'ing.

Reported-by: kernel test robot <lkp@intel.com>
Fixes: https://github.com/ClangBuiltLinux/linux/issues/1512

Diff Detail

Event Timeline

nickdesaulniers created this revision.Dec 8 2021, 4:52 PM
nickdesaulniers requested review of this revision.Dec 8 2021, 4:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2021, 4:52 PM
  • I'm just wrestling with arc at this point
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2021, 5:04 PM
nickdesaulniers added inline comments.Dec 8 2021, 5:49 PM
llvm/test/CodeGen/X86/callbr-asm-bb-exports.ll
23

@craig.topper can you triple check this change to this whole file carefully, please?

I'm not sure TBH why my change to SelectionDAGBuilder changed this. I'm also not sure of the original intent of the test. It's running -debug-only=isel which prints A LOT of different phases; I'm not sure which it was originally testing.

I'm not sure why we get an BlockAddress now; I don't really understand the output from selectionDAG here. (t16 looks unused to me, IIUC).

OK, I do think that special case definitely needs to be deleted. It's assuming that the block args are in a particular place in the argument list of the callbr -- the place Clang put them -- and then assigned special behavior based on that location. But I think it shouldn't do so -- they should be able to placed anywhere in the arglist.

The question then, is why this code needs to exist? It's accomplishing two things:

  1. If we get rid of this code but continue to use the "X" constraint, llvm won't emit an immediate symbol reference (today), rather, it will emit a register reference instead. Even though X means "accept anything", and therefore a register is thus supposedly acceptable, it seems like it should probably prefer emitting an immediate if it can. (GCC does emit it as an immediate here)
  2. Emits a TargetBlockAddress instead of BlockAddress. (I'm not sure what the use of TargetBlockAddress accomplishes? I _think_ it should be okay to use BlockAddress instead, but I'm not 100% sure...)

Assuming the point 2 is OK, then I think ideally, we'd flip the order of things, and do:
a. Cause "X" constraint to emit an immediate symbol reference if it can, rather than copying to a register first -- and remove this special case. (Fixes bug.)
b. Updates tests and change clang to emit "i" instead of "X" constraints. (Clarifies intent that an immediate is actually required).

craig.topper added inline comments.Dec 13 2021, 8:04 PM
llvm/test/CodeGen/X86/callbr-asm-bb-exports.ll
23

I think the important thing was that the t22 CopyFromReg chain output is used by the inlineasm_br.

I'm guessing the BlockAddress is being created by the getValue call in the else that is now reachable?

Maybe my regex to ignore most of the inlineasm_br line is hiding too much.

nickdesaulniers abandoned this revision.Dec 14 2021, 4:21 PM

OK, I do think that special case definitely needs to be deleted. It's assuming that the block args are in a particular place in the argument list of the callbr -- the place Clang put them -- and then assigned special behavior based on that location. But I think it shouldn't do so -- they should be able to placed anywhere in the arglist.

The question then, is why this code needs to exist? It's accomplishing two things:

  1. If we get rid of this code but continue to use the "X" constraint, llvm won't emit an immediate symbol reference (today), rather, it will emit a register reference instead. Even though X means "accept anything", and therefore a register is thus supposedly acceptable, it seems like it should probably prefer emitting an immediate if it can. (GCC does emit it as an immediate here)

Done in https://reviews.llvm.org/D115688. Closing this in favor of that. PTAL.

  1. Emits a TargetBlockAddress instead of BlockAddress. (I'm not sure what the use of TargetBlockAddress accomplishes? I _think_ it should be okay to use BlockAddress instead, but I'm not 100% sure...)

Not sure about this either way. Perhaps something for reviewers to consider.

Assuming the point 2 is OK, then I think ideally, we'd flip the order of things, and do:
a. Cause "X" constraint to emit an immediate symbol reference if it can, rather than copying to a register first -- and remove this special case. (Fixes bug.)
b. Updates tests and change clang to emit "i" instead of "X" constraints. (Clarifies intent that an immediate is actually required).

Now for me to rebase D115410, D115311, and D115471 onto D115688.

llvm/test/CodeGen/X86/callbr-asm-bb-exports.ll
23

Sounds like I should pre-commit (before D115688) a change that unrolls the regex?