[all-commits] [llvm/llvm-project] 6cdf6e: BPF: avoid NE/EQ loop exit condition

yonghong-song via All-commits all-commits at lists.llvm.org
Fri Aug 6 12:46:20 PDT 2021


  Branch: refs/heads/release/13.x
  Home:   https://github.com/llvm/llvm-project
  Commit: 6cdf6e50442cc2c9d19a241ab61db83cde80d416
      https://github.com/llvm/llvm-project/commit/6cdf6e50442cc2c9d19a241ab61db83cde80d416
  Author: Yonghong Song <yhs at fb.com>
  Date:   2021-08-06 (Fri, 06 Aug 2021)

  Changed paths:
    M llvm/lib/Target/BPF/BPFTargetTransformInfo.h
    A llvm/test/CodeGen/BPF/loop-exit-cond.ll

  Log Message:
  -----------
  BPF: avoid NE/EQ loop exit condition

Kuniyuki Iwashima reported in [1] that llvm compiler may
convert a loop exit condition with "i < bound" to "i != bound", where
"i" is the loop index variable and "bound" is the upper bound.
In case that "bound" is not a constant, verifier will always have "i != bound"
true, which will cause verifier failure since to verifier this is
an infinite loop.

The fix is to avoid transforming "i < bound" to "i != bound".
In llvm, the transformation is done by IndVarSimplify pass.
The compiler checks loop condition cost (i = i + 1) and if the
cost is lower, it may transform "i < bound" to "i != bound".
This patch implemented getArithmeticInstrCost() in BPF TargetTransformInfo
class to return a higher cost for such an operation, which
will prevent the transformation for the test case
added in this patch.

 [1] https://lore.kernel.org/netdev/1994df05-8f01-371f-3c3b-d33d7836878c@fb.com/

Differential Revision: https://reviews.llvm.org/D107483

(cherry picked from commit e52946b9ababcbf8e6f40b1b15900ae2e795a1c6)




More information about the All-commits mailing list