[PATCH] D150542: [ValueTracking] Ensure isGuaranteedNotToBeUndefOrPoison scans CtxI's parent basic block if CtxI is given
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 15 00:30:50 PDT 2023
StephenFan created this revision.
StephenFan added reviewers: nikic, goldstein.w.n, DaniilSuchkov.
Herald added a subscriber: hiraditya.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
As far as I known, if CtxI is given in isGuaranteedNotToBeUndefOrPoison,
it means that V is guaranteedNotToBeUndefOrPoison in CtxI's parent basic
block. However, in guaranteedNotToBeUndefOrPoison, we call
programUndefinedifUndefOrPoison that only scan's V's parent basic block
if V is instruction or entry block if V is argument. That will make
isGuaranteedNotToBePoisonOrUndef return incorrect result for the
following IR, and we call isGuaranteedNotToBePoisonOrUndef('%zext',
nullptr, '%x').
declare void @maythrow()
declare void @use.i32(i32)
define void @zext_sdiv_not_ok3_maybe_poison_denum(i32 noundef %nn, i16 %xx) {
entry:
%n = and i32 %nn, 123
%x = or i16 %xx, 1
br label %loop
loop:
call void @maythrow()
%zext = zext i16 %x to i32
%div = sdiv i32 %n, %zext
call void @use.i32(i32 %div)
br label %loop
}
Actually, `%zext` in block `entry` is not guaranteed not to be undef or
poison. But current `isGuarnateedNotToBePoisonOrUndef` calls
programUndefIfUndefOrPoison that scans `loop` block and it returns true
since there is a sdiv instruction that uses `%zext` as divisor.
And current `isSafeToSpeculativeExecute` has not called
`isGuaranteedNotToBePoison`, but it will happen if D149423 <https://reviews.llvm.org/D149423> is landed.
And then if we call `isSafeToSpeculativeExecute(`%div`, `%x`)`, it will
return true, which is wrong.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D150542
Files:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/PhaseOrdering/AArch64/matrix-extract-insert.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150542.522073.patch
Type: text/x-patch
Size: 12459 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230515/f45295d9/attachment.bin>
More information about the llvm-commits
mailing list