OSDN Git Service

bpf: Tighten subregister definition check
authorYonghong Song <yhs@fb.com>
Tue, 13 Mar 2018 06:47:00 +0000 (06:47 +0000)
committerYonghong Song <yhs@fb.com>
Tue, 13 Mar 2018 06:47:00 +0000 (06:47 +0000)
commitc543a072f894b6f8f30bcdf010e9e7f1ad6915dc
tree99da95e36d31b0934928bfc63aafe8e99b3a4f0a
parenta26a1c77ed7af2f0920cf1e30d008ee52223253e
bpf: Tighten subregister definition check

The current subregister definition check stops after the MOV_32_64
instruction.

This means we are thinking all the following instruction sequences
are safe to be eliminated:

  MOV_32_64 rB, wA
  SLL_ri    rB, rB, 32
  SRL_ri    rB, rB, 32

However, this is *not* true. The source subregister wA of MOV_32_64 could
come from a implicit truncation of 64-bit register in which case the high
bits of the 64-bit register is not zeroed, therefore we can't eliminate
above sequence.

For example, for i32_val, we shouldn't do the elimination:

  long long bar ();

  int foo (int b, int c)
  {
    unsigned int i32_val = (unsigned int) bar();

    if (i32_val < 10)
      return b;
    else
      return c;
  }

Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327365 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/BPF/BPFMIPeephole.cpp
test/CodeGen/BPF/32-bit-subreg-peephole.ll