[PATCH] D103954: [SLP] Incorrect handling of external scalar values

Evgeniy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 11 03:50:16 PDT 2021


ebrevnov updated this revision to Diff 351398.
ebrevnov added a comment.

Fix issue found by buildbot. Locs for Scalar should be requested after VectorMap.operator[] since it may invalidate those.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103954/new/

https://reviews.llvm.org/D103954

Files:
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/test/Transforms/SLPVectorizer/slp-hr-with-reuse.ll


Index: llvm/test/Transforms/SLPVectorizer/slp-hr-with-reuse.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/SLPVectorizer/slp-hr-with-reuse.ll
@@ -0,0 +1,44 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt --passes=slp-vectorizer,instcombine -slp-threshold=-1000000 -S < %s | FileCheck %s
+
+define i32 @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret i32 -162
+;
+entry:
+  %i = xor i32 4, -9
+  %i1 = xor i32 5, %i
+  %i2 = xor i32 6, %i1
+  %i3 = add i32 %i2, 0
+  %i4 = add i32 -9, %i3
+  %i5 = xor i32 8, -9
+  %i6 = add i32 %i5, %i4
+  %i7 = xor i32 9, %i5
+  %i8 = add i32 %i7, %i6
+  %i9 = xor i32 10, %i7
+  %i10 = add i32 %i9, %i8
+  %i11 = add i32 -9, %i10
+  %i12 = xor i32 12, -9
+  %i13 = add i32 %i12, %i11
+  %i14 = xor i32 13, %i12
+  %i15 = add i32 %i14, %i13
+  %i16 = xor i32 14, %i14
+  %i17 = add i32 %i16, %i15
+  %i18 = add i32 -9, %i17
+  %i19 = xor i32 16, -9
+  %i20 = add i32 %i19, %i18
+  %i21 = xor i32 17, %i19
+  %i22 = add i32 %i21, %i20
+  %i23 = xor i32 18, %i21
+  %i24 = add i32 %i23, %i22
+  %i25 = add i32 -9, %i24
+  %i26 = add i32 0, %i25
+  %i27 = add i32 0, %i26
+  %i28 = add i32 0, %i27
+  %i29 = add i32 -9, %i28
+  %i30 = add i32 0, %i29
+  %i31 = add i32 0, %i30
+  %i32 = add i32 0, %i31
+  ret i32 %i32
+}
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5713,8 +5713,11 @@
       }
       Value *NewInst = ExtractAndExtendIfNeeded(Vec);
       CSEBlocks.insert(cast<Instruction>(Scalar)->getParent());
-      auto &Locs = ExternallyUsedValues[Scalar];
-      ExternallyUsedValues.insert({NewInst, Locs});
+      auto &NewInstLocs = ExternallyUsedValues[NewInst];
+      auto It = ExternallyUsedValues.find(Scalar);
+      assert(It != ExternallyUsedValues.end() &&
+             "Externally used scalar is not found in ExternallyUsedValues");
+      NewInstLocs.append(It->second);
       ExternallyUsedValues.erase(Scalar);
       // Required to update internally referenced instructions.
       Scalar->replaceAllUsesWith(NewInst);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103954.351398.patch
Type: text/x-patch
Size: 2297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210611/2df3a792/attachment.bin>


More information about the llvm-commits mailing list