[PATCH] D24542: Make vector operation with variable index unsafe to speculate
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 13 20:18:27 PDT 2016
arsenm created this revision.
arsenm added a subscriber: llvm-commits.
Herald added a subscriber: wdng.
A branch condition could be guarding an out of bounds access of the vector.
https://reviews.llvm.org/D24542
Files:
lib/Analysis/ValueTracking.cpp
test/Transforms/SimplifyCFG/speculate-vector-ops.ll
Index: test/Transforms/SimplifyCFG/speculate-vector-ops.ll
===================================================================
--- test/Transforms/SimplifyCFG/speculate-vector-ops.ll
+++ test/Transforms/SimplifyCFG/speculate-vector-ops.ll
@@ -57,4 +57,40 @@
br label %return
}
+; CHECK-LABEL: @no_speculate_extractelement_varindex(
+; CHECK: br i1 %cmp
+; CHECK: extractelement
+; CHECK: phi
+define i32 @no_speculate_extractelement_varindex(i32 %c, i32 %idx) #0 {
+entry:
+ %cmp = icmp eq i32 %c, 0
+ br i1 %cmp, label %a, label %b
+
+a:
+ %x = extractelement <4 x i32> undef, i32 %idx
+ br label %b
+
+b:
+ %phi = phi i32 [ 0, %entry], [ %x, %a ]
+ ret i32 %phi
+}
+
+; CHECK-LABEL: @no_speculate_insertelement_varindex(
+; CHECK: br i1 %cmp
+; CHECK: insertelement
+; CHECK: phi
+define <4 x i32> @no_speculate_insertelement_varindex(i32 %c, i32 %idx) #0 {
+entry:
+ %cmp = icmp eq i32 %c, 0
+ br i1 %cmp, label %a, label %b
+
+a:
+ %x = insertelement <4 x i32> undef, i32 8, i32 %idx
+ br label %b
+
+b:
+ %phi = phi <4 x i32> [ zeroinitializer, %entry], [ %x, %a ]
+ ret <4 x i32> %phi
+}
+
attributes #0 = { nounwind }
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -3235,6 +3235,10 @@
return false; // The called function could have undefined behavior or
// side-effects, even if marked readnone nounwind.
}
+ case Instruction::ExtractElement:
+ return isa<Constant>(Inst->getOperand(1));
+ case Instruction::InsertElement:
+ return isa<Constant>(Inst->getOperand(2));
case Instruction::VAArg:
case Instruction::Alloca:
case Instruction::Invoke:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24542.71288.patch
Type: text/x-patch
Size: 1748 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160914/819b51f6/attachment.bin>
More information about the llvm-commits
mailing list