[all-commits] [llvm/llvm-project] c2eccc: [GuardWidening] Remove nuw/nsw flags for hoisted i...
serguei-katkov via All-commits
all-commits at lists.llvm.org
Wed May 25 23:32:10 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: c2eccc67ce07e9cb374eb0ecdb3038fcb8be08cd
https://github.com/llvm/llvm-project/commit/c2eccc67ce07e9cb374eb0ecdb3038fcb8be08cd
Author: Serguei Katkov <serguei.katkov at azul.com>
Date: 2022-05-26 (Thu, 26 May 2022)
Changed paths:
M llvm/lib/Transforms/Scalar/GuardWidening.cpp
M llvm/test/Transforms/GuardWidening/range-check-merging.ll
Log Message:
-----------
[GuardWidening] Remove nuw/nsw flags for hoisted instructions
When we hoist instructions over guard we must clear flags due to these flags
might be implied using this guard, so they make sense only after the guard.
As an example of the bug due to current behavior.
L is known to be in range say [0, 100)
c1 = x u< L
guard (c1)
x1 = add x, 1
c2 = x1 u< L
guard(c2)
basing on guard(c1) we can say that x1 = add nuw nsw x, 1
after guard widening we get
c1 = x u< L
x1 = add nuw nsw x, 1
c2 = x1 u< L
c = and c1, c2
guard(c)
now, basing on fact that x + 1 < L and x >= 0 due to x + 1 is nuw
we can prove that x + 1 u< L implies that x u< L, so we can just remove c1
x1 = add nuw nsw x, 1
c2 = x1 u< L
guard(c2)
But that is not correct due to we will pass x == -1 value.
Reviewed By: mkazantsev
Subscribers: llvm-commits, nikic
Differential Revision: https://reviews.llvm.org/D126354
More information about the All-commits
mailing list