[PATCH] D107483: BPF: avoid NE/EQ loop exit condition
Yonghong Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 4 10:38:23 PDT 2021
yonghong-song created this revision.
yonghong-song added a reviewer: ast.
Herald added a subscriber: hiraditya.
yonghong-song requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Kuniyuki Iwashima reported 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/
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107483
Files:
llvm/lib/Target/BPF/BPFTargetTransformInfo.h
llvm/test/CodeGen/BPF/loop-exit-cond.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107483.364181.patch
Type: text/x-patch
Size: 6377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210804/ea7746a4/attachment.bin>
More information about the llvm-commits
mailing list