forked from OSchip/llvm-project
[bpf] disallow global_addr+off folding
Wrong assembly code is generated for a simple program with clang. If clang only produces IR and llc is used for IR lowering and optimization, correct assembly code is generated. The main reason is that clang feeds default Reloc::Static to llvm and llc feeds no RelocMode to llvm, where for llc case, BPF backend picks up Reloc::PIC_ mode. This leads different IR lowering behavior and clang permits global_addr+off folding while llc doesn't. This patch introduces isOffsetFoldingLegal function into BPF backend and the function always return false. This will make clang and llc behave the same for the lowering. Bug https://bugs.llvm.org//show_bug.cgi?id=33183 has more detailed explanation. Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> llvm-svn: 304043
This commit is contained in:
parent
23d2f0d77a
commit
3c585d3a8f
|
@ -132,6 +132,10 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine &TM,
|
|||
MaxStoresPerMemmove = MaxStoresPerMemmoveOptSize = 128;
|
||||
}
|
||||
|
||||
bool BPFTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
SDValue BPFTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
|
||||
switch (Op.getOpcode()) {
|
||||
case ISD::BR_CC:
|
||||
|
@ -496,8 +500,11 @@ const char *BPFTargetLowering::getTargetNodeName(unsigned Opcode) const {
|
|||
|
||||
SDValue BPFTargetLowering::LowerGlobalAddress(SDValue Op,
|
||||
SelectionDAG &DAG) const {
|
||||
auto N = cast<GlobalAddressSDNode>(Op);
|
||||
assert(N->getOffset() == 0 && "Invalid offset for global address");
|
||||
|
||||
SDLoc DL(Op);
|
||||
const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
|
||||
const GlobalValue *GV = N->getGlobal();
|
||||
SDValue GA = DAG.getTargetGlobalAddress(GV, DL, MVT::i64);
|
||||
|
||||
return DAG.getNode(BPFISD::Wrapper, DL, MVT::i64, GA);
|
||||
|
|
|
@ -42,6 +42,10 @@ public:
|
|||
// This method returns the name of a target specific DAG node.
|
||||
const char *getTargetNodeName(unsigned Opcode) const override;
|
||||
|
||||
// This method decides whether folding a constant offset
|
||||
// with the given GlobalAddress is legal.
|
||||
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
|
||||
|
||||
MachineBasicBlock *
|
||||
EmitInstrWithCustomInserter(MachineInstr &MI,
|
||||
MachineBasicBlock *BB) const override;
|
||||
|
|
Loading…
Reference in New Issue