[llvm] 6a06155 - [VectorCombine] Discard ScalarizationResults if transform aborted

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 03:24:38 PDT 2023


Author: Nikita Popov
Date: 2023-10-31T11:24:30+01:00
New Revision: 6a06155c53344e7c276c7ccda5a3fb287937fff5

URL: https://github.com/llvm/llvm-project/commit/6a06155c53344e7c276c7ccda5a3fb287937fff5
DIFF: https://github.com/llvm/llvm-project/commit/6a06155c53344e7c276c7ccda5a3fb287937fff5.diff

LOG: [VectorCombine] Discard ScalarizationResults if transform aborted

Fixes https://github.com/llvm/llvm-project/issues/69820.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VectorCombine.cpp
    llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 51163352b1e6876..9a91ce207bb04c9 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -14,6 +14,7 @@
 
 #include "llvm/Transforms/Vectorize/VectorCombine.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/AssumptionCache.h"
 #include "llvm/Analysis/BasicAliasAnalysis.h"
@@ -1272,6 +1273,12 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
   Instruction *LastCheckedInst = LI;
   unsigned NumInstChecked = 0;
   DenseMap<ExtractElementInst *, ScalarizationResult> NeedFreeze;
+  auto FailureGuard = make_scope_exit([&]() {
+    // If the transform is aborted, discard the ScalarizationResults.
+    for (auto &Pair : NeedFreeze)
+      Pair.second.discard();
+  });
+
   // Check if all users of the load are extracts with no memory modifications
   // between the load and the extract. Compute the cost of both the original
   // code and the scalarized version.
@@ -1339,6 +1346,7 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
     replaceValue(*EI, *NewLoad);
   }
 
+  FailureGuard.release();
   return true;
 }
 

diff  --git a/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll b/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll
index 7d1c7a6855d7619..613c71cb769b0c9 100644
--- a/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll
+++ b/llvm/test/Transforms/VectorCombine/AArch64/load-extractelement-scalarization.ll
@@ -906,3 +906,24 @@ exit:
   %p = phi i8 [ 0, %entry ], [ %ext, %then ]
   ret i8 0
 }
+
+declare void @use(...)
+
+; Make sure we don't assert.
+define void @pr69820(ptr %p, i32 %arg) {
+; CHECK-LABEL: @pr69820(
+; CHECK-NEXT:    [[V:%.*]] = load <4 x float>, ptr [[P:%.*]], align 16
+; CHECK-NEXT:    [[AND:%.*]] = and i32 [[ARG:%.*]], 3
+; CHECK-NEXT:    [[EXT:%.*]] = extractelement <4 x float> [[V]], i32 [[AND]]
+; CHECK-NEXT:    call void @use(<4 x float> [[V]], float [[EXT]])
+; CHECK-NEXT:    ret void
+;
+  %v = load <4 x float>, ptr %p, align 16
+  %and = and i32 %arg, 3
+  %ext = extractelement <4 x float> %v, i32 %and
+  call void @use(<4 x float> %v, float %ext)
+  ret void
+
+; uselistorder directives
+  uselistorder <4 x float> %v, { 1, 0 }
+}


        


More information about the llvm-commits mailing list