D108961 introduced relaxation for out-of-range conditional branches.
However, relaxation was only performed when the branch target could be
resolved. I believe this has two undesired consequences:
- b<cc> ... foo, where foo is undefined, would not be relaxed although there is no guarantee the offset to foo will fit;
- Conditional branches are never relaxed with -mattr=+relax because MC considers fixups where shouldForceRelocation returns true (which will be the case with +relax) to be unresolved.
Note that binutils performs conditional branch relaxation in both cases.
This patch proposes to perform conditional branch relaxation even when
the target cannot be resolved.
Note on llvm/test/MC/RISCV/long-conditional-jump.s: I've removed the
.p2align because this causes alignment nops to be inserted for the
+relax tests. This in turn causes all the branch targets to change
compared to the non-+relax tests. Since +relax shouldn't change
these offsets, I found this confusing and hence chose to remove the
alignment.
Depends on D155953