[PATCH] D36590: [ValueTracking] don't delete assumes of side-effectful instructions
Ariel Ben-Yehuda via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 10 12:54:13 PDT 2017
arielb1 created this revision.
ValueTracking has to strike a balance when attempting to propagate information backwards from assumes, because if the information is trivially propagated backwards, it can appear to LLVM that the assumption is known to be true, and therefore can be removed.
This is sound (because an assumption has no semantic effect except for causing UB), but prevents the assume from allowing further optimizations.
The isEphemeralValueOf check exists to try and prevent this issue by not removing the source of an assumption. This tries to make it a little bit more general to handle the case of side-effectful instructions, such as in
%0 = call i1 @get_val()
%1 = xor i1 %0, true
call void @llvm.assume(i1 %1)
FIX: try to make llvm-commits see this
https://reviews.llvm.org/D36590
Files:
lib/Analysis/ValueTracking.cpp
test/Analysis/ValueTracking/assume.ll
Index: test/Analysis/ValueTracking/assume.ll
===================================================================
--- test/Analysis/ValueTracking/assume.ll
+++ test/Analysis/ValueTracking/assume.ll
@@ -18,5 +18,16 @@
ret i32 %t3
}
-declare void @llvm.assume(i1)
+define void @assume_not() {
+; CHECK-LABEL: @assume_not(
+entry-block:
+ %0 = call i1 @get_val()
+; CHECK: call void @llvm.assume
+ %1 = xor i1 %0, true
+ call void @llvm.assume(i1 %1)
+ ret void
+}
+
+declare i1 @get_val()
+declare void @llvm.assume(i1)
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -384,13 +384,13 @@
if (V == E)
return true;
- EphValues.insert(V);
- if (const User *U = dyn_cast<User>(V))
- for (User::const_op_iterator J = U->op_begin(), JE = U->op_end();
- J != JE; ++J) {
- if (isSafeToSpeculativelyExecute(*J))
- WorkSet.push_back(*J);
- }
+ if (V == I || isSafeToSpeculativelyExecute(V)) {
+ EphValues.insert(V);
+ if (const User *U = dyn_cast<User>(V))
+ for (User::const_op_iterator J = U->op_begin(), JE = U->op_end();
+ J != JE; ++J)
+ WorkSet.push_back(*J);
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36590.110625.patch
Type: text/x-patch
Size: 1340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170810/4f025966/attachment.bin>
More information about the llvm-commits
mailing list