Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-commit: test PR76384 #49

Closed
wants to merge 2 commits into from
Closed

pre-commit: test PR76384 #49

wants to merge 2 commits into from

Conversation

dtcxzyw
Copy link
Owner

@dtcxzyw dtcxzyw commented Dec 26, 2023

Copy link
Contributor

baseline: llvm/llvm-project@64e6388
patch: llvm/llvm-project#76384
sha256: 4d31e3677a63ea29e0de4325661177bcd88bf0bbce3da29cdfd4212451933170
commit: 1088c3c
1088c3c pre-commit: Update
bench/abseil-cpp/optimized/container_test.cc.ll
bench/abseil-cpp/optimized/convert_test.cc.ll
bench/abseil-cpp/optimized/cord_test.cc.ll
bench/abseil-cpp/optimized/cordz_info_test.cc.ll
bench/abseil-cpp/optimized/discrete_distribution_test.cc.ll
bench/abseil-cpp/optimized/explicit_seed_seq_test.cc.ll
bench/abseil-cpp/optimized/fixed_array_test.cc.ll
bench/abseil-cpp/optimized/hash_instantiated_test.cc.ll
bench/abseil-cpp/optimized/hash_test.cc.ll
bench/abseil-cpp/optimized/inlined_vector_test.cc.ll
bench/abseil-cpp/optimized/layout_test.cc.ll
bench/abseil-cpp/optimized/marshalling.cc.ll
bench/abseil-cpp/optimized/parse.cc.ll
bench/abseil-cpp/optimized/parser_test.cc.ll
bench/abseil-cpp/optimized/raw_hash_set_test.cc.ll
bench/abseil-cpp/optimized/reflection_test.cc.ll
bench/abseil-cpp/optimized/salted_seed_seq_test.cc.ll
bench/abseil-cpp/optimized/span_test.cc.ll
bench/abseil-cpp/optimized/statusor_test.cc.ll
bench/abseil-cpp/optimized/str_split_test.cc.ll
bench/abseil-cpp/optimized/vlog_config.cc.ll
bench/arrow/optimized/api_aggregate.cc.ll
bench/arrow/optimized/array_nested.cc.ll
bench/arrow/optimized/array_run_end.cc.ll
bench/arrow/optimized/atfork_internal.cc.ll
bench/arrow/optimized/bridge.cc.ll
bench/arrow/optimized/builder.cc.ll
bench/arrow/optimized/builder_nested.cc.ll
bench/arrow/optimized/builder_run_end.cc.ll
bench/arrow/optimized/builder_union.cc.ll
bench/arrow/optimized/caching.cc.ll
bench/arrow/optimized/csf_converter.cc.ll
bench/arrow/optimized/csx_converter.cc.ll
bench/arrow/optimized/dictionary.cc.ll
bench/arrow/optimized/diff.cc.ll
bench/arrow/optimized/expression.cc.ll
bench/arrow/optimized/feather.cc.ll
bench/arrow/optimized/function.cc.ll
bench/arrow/optimized/interfaces.cc.ll
bench/arrow/optimized/metadata_internal.cc.ll
bench/arrow/optimized/reader.cc.ll
bench/arrow/optimized/ree_util_internal.cc.ll
bench/arrow/optimized/row_internal.cc.ll
bench/arrow/optimized/scalar_cast_internal.cc.ll
bench/arrow/optimized/table.cc.ll
bench/arrow/optimized/tensor.cc.ll
bench/arrow/optimized/type.cc.ll
bench/arrow/optimized/tz.cpp.ll
bench/arrow/optimized/validate.cc.ll
bench/arrow/optimized/vector_selection_filter_internal.cc.ll
bench/arrow/optimized/vector_selection_internal.cc.ll
bench/arrow/optimized/writer.cc.ll
bench/assimp/optimized/3DSLoader.cpp.ll
bench/assimp/optimized/ACLoader.cpp.ll
bench/assimp/optimized/ASELoader.cpp.ll
bench/assimp/optimized/BlenderLoader.cpp.ll
bench/assimp/optimized/ColladaExporter.cpp.ll
bench/assimp/optimized/ColladaParser.cpp.ll
bench/assimp/optimized/FBXAnimation.cpp.ll
bench/assimp/optimized/FBXConverter.cpp.ll
bench/assimp/optimized/FBXDeformer.cpp.ll
bench/assimp/optimized/FBXDocument.cpp.ll
bench/assimp/optimized/FBXMeshGeometry.cpp.ll
bench/assimp/optimized/FBXModel.cpp.ll
bench/assimp/optimized/IFCBoolean.cpp.ll
bench/assimp/optimized/IFCCurve.cpp.ll
bench/assimp/optimized/IFCGeometry.cpp.ll
bench/assimp/optimized/IFCOpenings.cpp.ll
bench/assimp/optimized/IFCReaderGen1_2x3.cpp.ll
bench/assimp/optimized/IFCReaderGen2_2x3.cpp.ll
bench/assimp/optimized/IFCUtil.cpp.ll
bench/assimp/optimized/IRRLoader.cpp.ll
bench/assimp/optimized/IRRMeshLoader.cpp.ll
bench/assimp/optimized/LWOAnimation.cpp.ll
bench/assimp/optimized/LWOLoader.cpp.ll
bench/assimp/optimized/NFFLoader.cpp.ll
bench/assimp/optimized/ObjFileImporter.cpp.ll
bench/assimp/optimized/OgreXmlSerializer.cpp.ll
bench/assimp/optimized/STLLoader.cpp.ll
bench/assimp/optimized/X3DGeoHelper.cpp.ll
bench/assimp/optimized/X3DImporter_Geometry3D.cpp.ll
bench/assimp/optimized/X3DImporter_Metadata.cpp.ll
bench/assimp/optimized/X3DImporter_Rendering.cpp.ll
bench/assimp/optimized/XGLLoader.cpp.ll
bench/assimp/optimized/clipper.cpp.ll
bench/assimp/optimized/glTF2Exporter.cpp.ll
bench/assimp/optimized/glTFExporter.cpp.ll
bench/assimp/optimized/glTFImporter.cpp.ll
bench/bullet3/optimized/btSoftBodyHelpers.ll
bench/cpp-httplib/optimized/httplib.cc.ll
bench/cvc5/optimized/abduction_solver.cpp.ll
bench/cvc5/optimized/ackermann.cpp.ll
bench/cvc5/optimized/addition.cpp.ll
bench/cvc5/optimized/alethe_post_processor.cpp.ll
bench/cvc5/optimized/alf_node_converter.cpp.ll
bench/cvc5/optimized/arith_entail.cpp.ll
bench/cvc5/optimized/arith_poly_norm.cpp.ll
bench/cvc5/optimized/arith_rewriter.cpp.ll
bench/cvc5/optimized/array_info.cpp.ll

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/arrow/optimized/diff.cc.ll b/bench/arrow/optimized/diff.cc.ll
index 3b8dabdf..5c73dbcd 100644
--- a/bench/arrow/optimized/diff.cc.ll
+++ b/bench/arrow/optimized/diff.cc.ll
@@ -5668,6 +5668,7 @@ declare noundef zeroext i1 @_ZNK5arrow8DataType6EqualsERKSt10shared_ptrIS0_Eb(pt
 define linkonce_odr void @_ZN5arrow23QuadraticSpaceMyersDiff4DiffEv(ptr noalias sret(%"class.arrow::Result") align 8 %agg.result, ptr noundef nonnull align 8 dereferenceable(144) %this) local_unnamed_addr #0 comdat align 2 personality ptr @__gxx_personality_v0 {
 entry:
   %ref.tmp = alloca %"class.arrow::Result.118", align 8
+  %ref.tmp16.sroa.0 = alloca i64, align 8
   %ref.tmp27 = alloca [1 x i8], align 1
   %base_begin_ = getelementptr inbounds %"class.arrow::QuadraticSpaceMyersDiff", ptr %this, i64 0, i32 3
   store i64 0, ptr %base_begin_, align 8
@@ -5751,11 +5752,15 @@ _ZNSt10unique_ptrIN5arrow15ValueComparatorESt14default_deleteIS1_EED2Ev.exit: ;
 
 invoke.cont21:                                    ; preds = %_ZNSt10unique_ptrIN5arrow15ValueComparatorESt14default_deleteIS1_EED2Ev.exit
   %add.i = add nsw i64 %call2.i6, %14
+  store i64 %add.i, ptr %ref.tmp16.sroa.0, align 8
   %endpoint_base_ = getelementptr inbounds %"class.arrow::QuadraticSpaceMyersDiff", ptr %this, i64 0, i32 10
   %_M_end_of_storage.i.i = getelementptr inbounds %"class.arrow::QuadraticSpaceMyersDiff", ptr %this, i64 0, i32 10, i32 0, i32 0, i32 0, i32 2
   %19 = load ptr, ptr %_M_end_of_storage.i.i, align 8
   %20 = load ptr, ptr %endpoint_base_, align 8
-  %cmp.i8 = icmp eq ptr %19, %20
+  %sub.ptr.lhs.cast.i.i = ptrtoint ptr %19 to i64
+  %sub.ptr.rhs.cast.i.i = ptrtoint ptr %20 to i64
+  %sub.ptr.sub.i.i = sub i64 %sub.ptr.lhs.cast.i.i, %sub.ptr.rhs.cast.i.i
+  %cmp.i8 = icmp ult i64 %sub.ptr.sub.i.i, 8
   br i1 %cmp.i8, label %if.then.i, label %if.else.i
 
 if.then.i:                                        ; preds = %invoke.cont21
@@ -5765,11 +5770,11 @@ if.then.i:                                        ; preds = %invoke.cont21
 call5.i.i.i.i.i.noexc:                            ; preds = %if.then.i
   store i64 %add.i, ptr %call5.i.i.i.i.i9, align 8
   %_M_finish.i = getelementptr inbounds %"class.arrow::QuadraticSpaceMyersDiff", ptr %this, i64 0, i32 10, i32 0, i32 0, i32 0, i32 1
-  %tobool.not.i.i = icmp eq ptr %19, null
+  %tobool.not.i.i = icmp eq ptr %20, null
   br i1 %tobool.not.i.i, label %_ZNSt12_Vector_baseIlSaIlEE13_M_deallocateEPlm.exit.i, label %if.then.i13.i
 
 if.then.i13.i:                                    ; preds = %call5.i.i.i.i.i.noexc
-  call void @_ZdlPv(ptr noundef nonnull %19) #20
+  call void @_ZdlPv(ptr noundef nonnull %20) #20
   br label %_ZNSt12_Vector_baseIlSaIlEE13_M_deallocateEPlm.exit.i
 
 _ZNSt12_Vector_baseIlSaIlEE13_M_deallocateEPlm.exit.i: ; preds = %if.then.i13.i, %call5.i.i.i.i.i.noexc
@@ -5782,11 +5787,13 @@ _ZNSt12_Vector_baseIlSaIlEE13_M_deallocateEPlm.exit.i: ; preds = %if.then.i13.i,
 if.else.i:                                        ; preds = %invoke.cont21
   %_M_finish.i.i = getelementptr inbounds %"class.arrow::QuadraticSpaceMyersDiff", ptr %this, i64 0, i32 10, i32 0, i32 0, i32 0, i32 1
   %21 = load ptr, ptr %_M_finish.i.i, align 8
-  %cmp24.not.i = icmp eq ptr %21, %20
-  store i64 %add.i, ptr %20, align 8
-  br i1 %cmp24.not.i, label %_ZSt22__uninitialized_copy_aIPKlPllET0_T_S4_S3_RSaIT1_E.exit.i, label %if.then25.i
+  %sub.ptr.lhs.cast.i14.i = ptrtoint ptr %21 to i64
+  %sub.ptr.sub.i16.i = sub i64 %sub.ptr.lhs.cast.i14.i, %sub.ptr.rhs.cast.i.i
+  %cmp24.not.i = icmp ult i64 %sub.ptr.sub.i16.i, 8
+  br i1 %cmp24.not.i, label %_ZSt7advanceIPKlmEvRT_T0_.exit.i, label %if.then25.i
 
 if.then25.i:                                      ; preds = %if.else.i
+  store i64 %add.i, ptr %20, align 8
   %.pre.i = load ptr, ptr %_M_finish.i.i, align 8
   %add.ptr.i.i.i.i.i.i = getelementptr inbounds i64, ptr %20, i64 1
   %tobool.not.i19.i = icmp eq ptr %.pre.i, %add.ptr.i.i.i.i.i.i
@@ -5796,12 +5803,23 @@ invoke.cont.i.i:                                  ; preds = %if.then25.i
   store ptr %add.ptr.i.i.i.i.i.i, ptr %_M_finish.i.i, align 8
   br label %invoke.cont24
 
-_ZSt22__uninitialized_copy_aIPKlPllET0_T_S4_S3_RSaIT1_E.exit.i: ; preds = %if.else.i
-  %add.ptr.i.i.i.i.i.i.i.i.i = getelementptr inbounds i64, ptr %20, i64 1
+_ZSt7advanceIPKlmEvRT_T0_.exit.i:                 ; preds = %if.else.i
+  %tobool.not.i.i.i.i.i28.i = icmp eq ptr %21, %20
+  br i1 %tobool.not.i.i.i.i.i28.i, label %if.then.i.i.i.i.i.i.i.i.i, label %if.then.i.i.i.i.i29.i
+
+if.then.i.i.i.i.i29.i:                            ; preds = %_ZSt7advanceIPKlmEvRT_T0_.exit.i
+  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %20, ptr nonnull align 8 %ref.tmp16.sroa.0, i64 %sub.ptr.sub.i16.i, i1 false)
+  %.pre51.i = load ptr, ptr %_M_finish.i.i, align 8
+  br label %if.then.i.i.i.i.i.i.i.i.i
+
+if.then.i.i.i.i.i.i.i.i.i:                        ; preds = %_ZSt7advanceIPKlmEvRT_T0_.exit.i, %if.then.i.i.i.i.i29.i
+  %22 = phi ptr [ %20, %_ZSt7advanceIPKlmEvRT_T0_.exit.i ], [ %.pre51.i, %if.then.i.i.i.i.i29.i ]
+  store i64 %add.i, ptr %22, align 8
+  %add.ptr.i.i.i.i.i.i.i.i.i = getelementptr inbounds i64, ptr %22, i64 1
   store ptr %add.ptr.i.i.i.i.i.i.i.i.i, ptr %_M_finish.i.i, align 8
   br label %invoke.cont24
 
-invoke.cont24:                                    ; preds = %_ZNSt12_Vector_baseIlSaIlEE13_M_deallocateEPlm.exit.i, %if.then25.i, %invoke.cont.i.i, %_ZSt22__uninitialized_copy_aIPKlPllET0_T_S4_S3_RSaIT1_E.exit.i
+invoke.cont24:                                    ; preds = %_ZNSt12_Vector_baseIlSaIlEE13_M_deallocateEPlm.exit.i, %if.then25.i, %invoke.cont.i.i, %if.then.i.i.i.i.i.i.i.i.i
   store i8 1, ptr %ref.tmp27, align 1
   %insert_ = getelementptr inbounds %"class.arrow::QuadraticSpaceMyersDiff", ptr %this, i64 0, i32 11
   %add.ptr.i.i7 = getelementptr inbounds i8, ptr %ref.tmp27, i64 1
@@ -5809,19 +5827,19 @@ invoke.cont24:                                    ; preds = %_ZNSt12_Vector_base
           to label %invoke.cont32 unwind label %lpad.loopexit.split-lp
 
 invoke.cont32:                                    ; preds = %invoke.cont24
-  %22 = load i64, ptr %base_end_, align 8
-  %23 = load i64, ptr %base_begin_, align 8
-  %sub = sub nsw i64 %22, %23
-  %24 = load i64, ptr %target_end_, align 8
-  %25 = load i64, ptr %target_begin_, align 8
-  %sub38 = sub nsw i64 %24, %25
+  %23 = load i64, ptr %base_end_, align 8
+  %24 = load i64, ptr %base_begin_, align 8
+  %sub = sub nsw i64 %23, %24
+  %25 = load i64, ptr %target_end_, align 8
+  %26 = load i64, ptr %target_begin_, align 8
+  %sub38 = sub nsw i64 %25, %26
   %cmp = icmp eq i64 %sub, %sub38
   br i1 %cmp, label %land.lhs.true, label %while.cond.preheader
 
 land.lhs.true:                                    ; preds = %invoke.cont32
-  %26 = load ptr, ptr %endpoint_base_, align 8
-  %27 = load i64, ptr %26, align 8
-  %cmp42 = icmp eq i64 %27, %22
+  %27 = load ptr, ptr %endpoint_base_, align 8
+  %28 = load i64, ptr %27, align 8
+  %cmp42 = icmp eq i64 %28, %23
   br i1 %cmp42, label %if.then43, label %while.cond.preheader
 
 if.then43:                                        ; preds = %land.lhs.true
@@ -5832,8 +5850,8 @@ while.cond.preheader:                             ; preds = %if.then43, %land.lh
   br label %while.cond
 
 while.cond:                                       ; preds = %while.cond.preheader, %while.body
-  %28 = load i64, ptr %finish_index_, align 8
-  %cmp.i.not = icmp eq i64 %28, -1
+  %29 = load i64, ptr %finish_index_, align 8
+  %cmp.i.not = icmp eq i64 %29, -1
   br i1 %cmp.i.not, label %while.body, label %while.end
 
 while.body:                                       ; preds = %while.cond
@@ -5842,8 +5860,8 @@ while.body:                                       ; preds = %while.cond
 
 while.end:                                        ; preds = %while.cond
   %pool_ = getelementptr inbounds %"class.arrow::QuadraticSpaceMyersDiff", ptr %this, i64 0, i32 2
-  %29 = load ptr, ptr %pool_, align 8
-  invoke void @_ZN5arrow23QuadraticSpaceMyersDiff8GetEditsEPNS_10MemoryPoolE(ptr sret(%"class.arrow::Result") align 8 %agg.result, ptr noundef nonnull align 8 dereferenceable(144) %this, ptr noundef %29)
+  %30 = load ptr, ptr %pool_, align 8
+  invoke void @_ZN5arrow23QuadraticSpaceMyersDiff8GetEditsEPNS_10MemoryPoolE(ptr sret(%"class.arrow::Result") align 8 %agg.result, ptr noundef nonnull align 8 dereferenceable(144) %this, ptr noundef %30)
           to label %cleanup unwind label %lpad.loopexit.split-lp
 
 cleanup:                                          ; preds = %while.end, %if.then

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/arrow/optimized/tz.cpp.ll b/bench/arrow/optimized/tz.cpp.ll
index 5f76c84d..cc65491d 100644
--- a/bench/arrow/optimized/tz.cpp.ll
+++ b/bench/arrow/optimized/tz.cpp.ll
@@ -1162,8 +1162,7 @@ _ZN14arrow_vendored4dateL6parse3B5cxx11ERSi.exit.i.i.i: ; preds = %invoke.cont12
 invoke.cont.i31.i.i:                              ; preds = %_ZN14arrow_vendored4dateL6parse3B5cxx11ERSi.exit.i.i.i
   %sub.ptr.lhs.cast.i.i.i = ptrtoint ptr %call.i.i4.i.i.i to i64
   %sub.ptr.sub.i.i.i = sub i64 %sub.ptr.lhs.cast.i.i.i, %sub.ptr.rhs.cast.i.i.i
-  %sub.ptr.div.i.i.i = ashr exact i64 %sub.ptr.sub.i.i.i, 3
-  %cmp.not.i.i70.i = icmp slt i64 %sub.ptr.div.i.i.i, 12
+  %cmp.not.i.i70.i = icmp slt i64 %sub.ptr.sub.i.i.i, 96
   br i1 %cmp.not.i.i70.i, label %invoke.cont45.i.i, label %if.then.i.i71.i
 
 if.then.i.i71.i:                                  ; preds = %invoke.cont.i31.i.i
@@ -1223,24 +1222,27 @@ invoke.cont45.i.i:                                ; preds = %invoke.cont.i31.i.i
           to label %invoke.cont67.i.i unwind label %lpad37.loopexit.i.i, !noalias !17
 
 invoke.cont67.i.i:                                ; preds = %invoke.cont45.i.i
-  %55 = trunc i64 %sub.ptr.div.i.i.i to i8
+  %55 = trunc i64 %sub.ptr.sub.i.i.i to i32
   %56 = load i32, ptr %y.i.i, align 4, !noalias !17
-  %57 = load i32, ptr %d.i.i, align 4, !noalias !17
-  %58 = add i8 %55, 1
+  %57 = shl i32 %55, 13
+  %retval.sroa.2.0.insert.shift.i.i.i.i = add i32 %57, 65536
+  %58 = load i32, ptr %d.i.i, align 4, !noalias !17
+  %ref.tmp53.sroa.2.0.extract.shift.i.i = lshr i32 %retval.sroa.2.0.insert.shift.i.i.i.i, 16
+  %ref.tmp53.sroa.2.0.extract.trunc.i.i = trunc i32 %ref.tmp53.sroa.2.0.extract.shift.i.i to i8
   %sext.i.i = shl i32 %56, 16
   %conv.i.i.i.i.i = ashr exact i32 %sext.i.i, 16
-  %cmp.i.i.i.i.i.i = icmp ult i8 %58, 3
+  %cmp.i.i.i.i.i.i = icmp ult i8 %ref.tmp53.sroa.2.0.extract.trunc.i.i, 3
   %conv.neg.i.i.i.i = sext i1 %cmp.i.i.i.i.i.i to i32
   %sub.i.i.i72.i = add nsw i32 %conv.i.i.i.i.i, %conv.neg.i.i.i.i
-  %conv.i11.i.i.i.i = zext i8 %58 to i32
-  %conv.i12.i.i.i.i = and i32 %57, 255
+  %conv.i11.i.i.i.i = and i32 %ref.tmp53.sroa.2.0.extract.shift.i.i, 255
+  %conv.i12.i.i.i.i = and i32 %58, 255
   %sub6.i.i.i.i = add nsw i32 %sub.i.i.i72.i, -399
   %cmp9.i.i.i.i = icmp slt i32 %sub.i.i.i72.i, 0
   %cond.i.i.i.i = select i1 %cmp9.i.i.i.i, i32 %sub6.i.i.i.i, i32 %sub.i.i.i72.i
   %div.i.i.i.i = sdiv i32 %cond.i.i.i.i, 400
   %mul.neg.i.i.i.i = mul nsw i32 %div.i.i.i.i, -400
   %sub7.i.i.i.i = add nsw i32 %mul.neg.i.i.i.i, %sub.i.i.i72.i
-  %cmp8.i.i.i.i = icmp ugt i8 %58, 2
+  %cmp8.i.i.i.i = icmp ugt i8 %ref.tmp53.sroa.2.0.extract.trunc.i.i, 2
   %cond13.v.i.i.i.i = select i1 %cmp8.i.i.i.i, i32 -3, i32 9
   %cond13.i.i.i.i = add nsw i32 %cond13.v.i.i.i.i, %conv.i11.i.i.i.i
   %mul14.i.i.i.i = mul nsw i32 %cond13.i.i.i.i, 153

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/assimp/optimized/XGLLoader.cpp.ll b/bench/assimp/optimized/XGLLoader.cpp.ll
index ea18db51..6aa9a70f 100644
--- a/bench/assimp/optimized/XGLLoader.cpp.ll
+++ b/bench/assimp/optimized/XGLLoader.cpp.ll
@@ -3266,16 +3266,20 @@ if.then27:                                        ; preds = %invoke.cont25
   %sub.ptr.lhs.cast.i58 = ptrtoint ptr %9 to i64
   %sub.ptr.rhs.cast.i59 = ptrtoint ptr %10 to i64
   %sub.ptr.sub.i60 = sub i64 %sub.ptr.lhs.cast.i58, %sub.ptr.rhs.cast.i59
+  %cmp308.not = icmp eq i64 %sub.ptr.sub.i60, %sub.ptr.sub.i
+  br i1 %cmp308.not, label %if.end108, label %for.body31.preheader
+
+for.body31.preheader:                             ; preds = %if.then27
   %sub.ptr.div.i61 = ashr exact i64 %sub.ptr.sub.i60, 3
   %sub = sub nsw i64 %sub.ptr.div.i61, %sub.ptr.div.i
-  %cmp308.not = icmp eq i64 %sub.ptr.div.i61, %sub.ptr.div.i
-  br i1 %cmp308.not, label %if.end108, label %for.body31
-
-for.body31:                                       ; preds = %if.then27, %for.inc
-  %i.0312 = phi i64 [ %inc, %for.inc ], [ 0, %if.then27 ]
-  %meshes.sroa.0.1311 = phi ptr [ %meshes.sroa.0.2, %for.inc ], [ %meshes.sroa.0.0320, %if.then27 ]
-  %meshes.sroa.10.1310 = phi ptr [ %meshes.sroa.10.2, %for.inc ], [ %meshes.sroa.10.0319, %if.then27 ]
-  %meshes.sroa.20.1309 = phi ptr [ %meshes.sroa.20.2, %for.inc ], [ %meshes.sroa.20.0318, %if.then27 ]
+  %umax = call i64 @llvm.umax.i64(i64 %sub, i64 1)
+  br label %for.body31
+
+for.body31:                                       ; preds = %for.body31.preheader, %for.inc
+  %i.0312 = phi i64 [ %inc, %for.inc ], [ 0, %for.body31.preheader ]
+  %meshes.sroa.0.1311 = phi ptr [ %meshes.sroa.0.2, %for.inc ], [ %meshes.sroa.0.0320, %for.body31.preheader ]
+  %meshes.sroa.10.1310 = phi ptr [ %meshes.sroa.10.2, %for.inc ], [ %meshes.sroa.10.0319, %for.body31.preheader ]
+  %meshes.sroa.20.1309 = phi ptr [ %meshes.sroa.20.2, %for.inc ], [ %meshes.sroa.20.0318, %for.body31.preheader ]
   %add = add i64 %i.0312, %sub.ptr.div.i
   %conv = trunc i64 %add to i32
   %cmp.not.i.i = icmp eq ptr %meshes.sroa.10.1310, %meshes.sroa.20.1309
@@ -3344,7 +3348,7 @@ for.inc:                                          ; preds = %_ZNSt6vectorIjSaIjE
   %meshes.sroa.0.2 = phi ptr [ %cond.i10.i.i.i, %_ZNSt6vectorIjSaIjEE17_M_realloc_insertIJjEEEvN9__gnu_cxx17__normal_iteratorIPjS1_EEDpOT_.exit.i.i ], [ %meshes.sroa.0.1311, %if.then.i.i ]
   %meshes.sroa.10.2 = getelementptr inbounds i32, ptr %add.ptr.i.i.i.pn, i64 1
   %inc = add nuw i64 %i.0312, 1
-  %exitcond383.not = icmp eq i64 %inc, %sub
+  %exitcond383.not = icmp eq i64 %inc, %umax
   br i1 %exitcond383.not, label %if.end108, label %for.body31, !llvm.loop !36
 
 lpad:                                             ; preds = %entry
@@ -6940,7 +6944,7 @@ invoke.cont:                                      ; preds = %entry
 new.ctorloop:                                     ; preds = %invoke.cont
   %3 = add nsw i64 %2, -12
   %4 = urem i64 %3, 12
-  %5 = sub nsw i64 %3, %4
+  %5 = sub nuw nsw i64 %3, %4
   %6 = add nsw i64 %5, 12
   tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %call7, i8 0, i64 %6, i1 false)
   br label %arrayctor.cont
@@ -6972,7 +6976,7 @@ invoke.cont25:                                    ; preds = %if.then
 new.ctorloop28:                                   ; preds = %invoke.cont25
   %9 = add nsw i64 %2, -12
   %10 = urem i64 %9, 12
-  %11 = sub nsw i64 %9, %10
+  %11 = sub nuw nsw i64 %9, %10
   %12 = add nsw i64 %11, 12
   tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %call26, i8 0, i64 %12, i1 false)
   br label %_ZSt4copyIN9__gnu_cxx17__normal_iteratorIPK10aiVector3tIfESt6vectorIS3_SaIS3_EEEEPS3_ET0_T_SC_SB_.exit38
@@ -7028,7 +7032,7 @@ arrayctor.cont65.thread:                          ; preds = %invoke.cont56
 for.body.preheader:                               ; preds = %invoke.cont56
   %16 = add nsw i64 %15, -12
   %17 = urem i64 %16, 12
-  %18 = sub nsw i64 %16, %17
+  %18 = sub nuw nsw i64 %16, %17
   %19 = add nsw i64 %18, 12
   tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %call57, i8 0, i64 %19, i1 false)
   %mTextureCoords = getelementptr inbounds %struct.aiMesh, ptr %call, i64 0, i32 8
@@ -19863,7 +19867,7 @@ _ZSt13move_backwardIN9__gnu_cxx17__normal_iteratorIPjSt6vectorIjSaIjEEEES6_ET0_T
   %sub.ptr.div.i.i.i.i.i.i58 = ashr exact i64 %sub.ptr.sub.i.i.i.i.i.i57, 2
   %.pre.i.i.i.i.i.i59 = sub nsw i64 0, %sub.ptr.div.i.i.i.i.i.i58
   %add.ptr.i.i.i.i.i.i60 = getelementptr inbounds i32, ptr %add.ptr.i2.i55, i64 %.pre.i.i.i.i.i.i59
-  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 4 %add.ptr.i.i.i.i.i.i60, ptr nonnull align 4 %__first.coerce, i64 %sub.ptr.sub.i.i.i.i.i.i57, i1 false)
+  tail call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %add.ptr.i.i.i.i.i.i60, ptr noundef nonnull align 4 dereferenceable(1) %__first.coerce, i64 %sub.ptr.sub.i.i.i.i.i.i57, i1 false)
   br label %for.inc.i40
 
 if.else.i35:                                      ; preds = %for.body.i25

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/hermes/optimized/CFG.cpp.ll b/bench/hermes/optimized/CFG.cpp.ll
index aae19d98..a6cca217 100644
--- a/bench/hermes/optimized/CFG.cpp.ll
+++ b/bench/hermes/optimized/CFG.cpp.ll
@@ -9244,7 +9244,7 @@ if.then3:                                         ; preds = %for.body
   %sub.ptr.div.i.i.i.i.i = ashr exact i64 %sub.ptr.sub.i.i.i.i.i, 4
   %.pre.i.i.i.i.i = sub nsw i64 0, %sub.ptr.div.i.i.i.i.i
   %add.ptr.i.i.i.i.i = getelementptr inbounds %"class.llvh::cfg::Update", ptr %add.ptr4, i64 %.pre.i.i.i.i.i
-  call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %add.ptr.i.i.i.i.i, ptr nonnull align 8 %__first, i64 %sub.ptr.sub.i.i.i.i.i, i1 false)
+  call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %add.ptr.i.i.i.i.i, ptr noundef nonnull align 8 dereferenceable(1) %__first, i64 %sub.ptr.sub.i.i.i.i.i, i1 false)
   call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %__first, ptr noundef nonnull align 8 dereferenceable(16) %__val, i64 16, i1 false)
   br label %for.inc
 
@@ -20452,21 +20452,26 @@ _ZN4llvh12DenseMapBaseINS_8DenseMapIPN6hermes10BasicBlockESt10unique_ptrINS_15Do
 ; Function Attrs: mustprogress nounwind uwtable
 define linkonce_odr hidden void @_ZN4llvh14DomTreeBuilder11SemiNCAInfoINS_17DominatorTreeBaseIN6hermes10BasicBlockELb0EEEE5clearEv(ptr noundef nonnull align 8 dereferenceable(56) %this) local_unnamed_addr #0 comdat align 2 {
 entry:
+  %ref.tmp.sroa.0 = alloca ptr, align 8
+  store ptr null, ptr %ref.tmp.sroa.0, align 8
   %_M_end_of_storage.i.i = getelementptr inbounds %"struct.std::_Vector_base<hermes::BasicBlock *, std::allocator<hermes::BasicBlock *>>::_Vector_impl_data", ptr %this, i64 0, i32 2
   %0 = load ptr, ptr %_M_end_of_storage.i.i, align 8
   %1 = load ptr, ptr %this, align 8
-  %cmp.i2 = icmp eq ptr %0, %1
+  %sub.ptr.lhs.cast.i.i = ptrtoint ptr %0 to i64
+  %sub.ptr.rhs.cast.i.i = ptrtoint ptr %1 to i64
+  %sub.ptr.sub.i.i = sub i64 %sub.ptr.lhs.cast.i.i, %sub.ptr.rhs.cast.i.i
+  %cmp.i2 = icmp ult i64 %sub.ptr.sub.i.i, 8
   br i1 %cmp.i2, label %if.then.i, label %if.else.i
 
 if.then.i:                                        ; preds = %entry
   %call5.i.i.i.i.i = tail call noalias noundef nonnull dereferenceable(8) ptr @_Znwm(i64 noundef 8) #14
   store i64 0, ptr %call5.i.i.i.i.i, align 8
   %_M_finish.i = getelementptr inbounds %"struct.std::_Vector_base<hermes::BasicBlock *, std::allocator<hermes::BasicBlock *>>::_Vector_impl_data", ptr %this, i64 0, i32 1
-  %tobool.not.i.i = icmp eq ptr %0, null
+  %tobool.not.i.i = icmp eq ptr %1, null
   br i1 %tobool.not.i.i, label %_ZNSt12_Vector_baseIPN6hermes10BasicBlockESaIS2_EE13_M_deallocateEPS2_m.exit.i, label %if.then.i13.i
 
 if.then.i13.i:                                    ; preds = %if.then.i
-  tail call void @_ZdlPv(ptr noundef nonnull %0) #12
+  tail call void @_ZdlPv(ptr noundef nonnull %1) #12
   br label %_ZNSt12_Vector_baseIPN6hermes10BasicBlockESaIS2_EE13_M_deallocateEPS2_m.exit.i
 
 _ZNSt12_Vector_baseIPN6hermes10BasicBlockESaIS2_EE13_M_deallocateEPS2_m.exit.i: ; preds = %if.then.i13.i, %if.then.i
@@ -20479,11 +20484,13 @@ _ZNSt12_Vector_baseIPN6hermes10BasicBlockESaIS2_EE13_M_deallocateEPS2_m.exit.i:
 if.else.i:                                        ; preds = %entry
   %_M_finish.i.i = getelementptr inbounds %"struct.std::_Vector_base<hermes::BasicBlock *, std::allocator<hermes::BasicBlock *>>::_Vector_impl_data", ptr %this, i64 0, i32 1
   %2 = load ptr, ptr %_M_finish.i.i, align 8
-  %cmp24.not.i = icmp eq ptr %2, %1
-  store i64 0, ptr %1, align 8
-  br i1 %cmp24.not.i, label %_ZSt22__uninitialized_copy_aIPKPN6hermes10BasicBlockEPS2_S2_ET0_T_S7_S6_RSaIT1_E.exit.i, label %if.then25.i
+  %sub.ptr.lhs.cast.i14.i = ptrtoint ptr %2 to i64
+  %sub.ptr.sub.i16.i = sub i64 %sub.ptr.lhs.cast.i14.i, %sub.ptr.rhs.cast.i.i
+  %cmp24.not.i = icmp ult i64 %sub.ptr.sub.i16.i, 8
+  br i1 %cmp24.not.i, label %_ZSt7advanceIPKPN6hermes10BasicBlockEmEvRT_T0_.exit.i, label %if.then25.i
 
 if.then25.i:                                      ; preds = %if.else.i
+  store i64 0, ptr %1, align 8
   %.pre.i = load ptr, ptr %_M_finish.i.i, align 8
   %add.ptr.i.i.i.i.i.i3 = getelementptr inbounds ptr, ptr %1, i64 1
   %tobool.not.i19.i = icmp eq ptr %.pre.i, %add.ptr.i.i.i.i.i.i3
@@ -20493,28 +20500,39 @@ if.then.i20.i:                                    ; preds = %if.then25.i
   store ptr %add.ptr.i.i.i.i.i.i3, ptr %_M_finish.i.i, align 8
   br label %_ZNSt6vectorIPN6hermes10BasicBlockESaIS2_EE13_M_assign_auxIPKS2_EEvT_S8_St20forward_iterator_tag.exit
 
-_ZSt22__uninitialized_copy_aIPKPN6hermes10BasicBlockEPS2_S2_ET0_T_S7_S6_RSaIT1_E.exit.i: ; preds = %if.else.i
-  %add.ptr.i.i.i.i.i.i.i.i.i = getelementptr inbounds ptr, ptr %1, i64 1
+_ZSt7advanceIPKPN6hermes10BasicBlockEmEvRT_T0_.exit.i: ; preds = %if.else.i
+  %tobool.not.i.i.i.i.i29.i = icmp eq ptr %2, %1
+  br i1 %tobool.not.i.i.i.i.i29.i, label %if.then.i.i.i.i.i.i.i.i.i, label %if.then.i.i.i.i.i30.i
+
+if.then.i.i.i.i.i30.i:                            ; preds = %_ZSt7advanceIPKPN6hermes10BasicBlockEmEvRT_T0_.exit.i
+  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %1, ptr nonnull align 8 %ref.tmp.sroa.0, i64 %sub.ptr.sub.i16.i, i1 false)
+  %.pre52.i = load ptr, ptr %_M_finish.i.i, align 8
+  br label %if.then.i.i.i.i.i.i.i.i.i
+
+if.then.i.i.i.i.i.i.i.i.i:                        ; preds = %_ZSt7advanceIPKPN6hermes10BasicBlockEmEvRT_T0_.exit.i, %if.then.i.i.i.i.i30.i
+  %3 = phi ptr [ %1, %_ZSt7advanceIPKPN6hermes10BasicBlockEmEvRT_T0_.exit.i ], [ %.pre52.i, %if.then.i.i.i.i.i30.i ]
+  store i64 0, ptr %3, align 8
+  %add.ptr.i.i.i.i.i.i.i.i.i = getelementptr inbounds ptr, ptr %3, i64 1
   store ptr %add.ptr.i.i.i.i.i.i.i.i.i, ptr %_M_finish.i.i, align 8
   br label %_ZNSt6vectorIPN6hermes10BasicBlockESaIS2_EE13_M_assign_auxIPKS2_EEvT_S8_St20forward_iterator_tag.exit
 
-_ZNSt6vectorIPN6hermes10BasicBlockESaIS2_EE13_M_assign_auxIPKS2_EEvT_S8_St20forward_iterator_tag.exit: ; preds = %_ZNSt12_Vector_baseIPN6hermes10BasicBlockESaIS2_EE13_M_deallocateEPS2_m.exit.i, %if.then25.i, %if.then.i20.i, %_ZSt22__uninitialized_copy_aIPKPN6hermes10BasicBlockEPS2_S2_ET0_T_S7_S6_RSaIT1_E.exit.i
+_ZNSt6vectorIPN6hermes10BasicBlockESaIS2_EE13_M_assign_auxIPKS2_EEvT_S8_St20forward_iterator_tag.exit: ; preds = %_ZNSt12_Vector_baseIPN6hermes10BasicBlockESaIS2_EE13_M_deallocateEPS2_m.exit.i, %if.then25.i, %if.then.i20.i, %if.then.i.i.i.i.i.i.i.i.i
   %NodeToInfo = getelementptr inbounds %"struct.llvh::DomTreeBuilder::SemiNCAInfo", ptr %this, i64 0, i32 1
   %NumEntries.i.i.i = getelementptr inbounds %"struct.llvh::DomTreeBuilder::SemiNCAInfo", ptr %this, i64 0, i32 1, i32 1
-  %3 = load i32, ptr %NumEntries.i.i.i, align 8
-  %cmp.i = icmp eq i32 %3, 0
+  %4 = load i32, ptr %NumEntries.i.i.i, align 8
+  %cmp.i = icmp eq i32 %4, 0
   %NumTombstones.i.i.i = getelementptr inbounds %"struct.llvh::DomTreeBuilder::SemiNCAInfo", ptr %this, i64 0, i32 1, i32 2
-  %4 = load i32, ptr %NumTombstones.i.i.i, align 4
-  %cmp3.i = icmp eq i32 %4, 0
+  %5 = load i32, ptr %NumTombstones.i.i.i, align 4
+  %cmp3.i = icmp eq i32 %5, 0
   %or.cond = select i1 %cmp.i, i1 %cmp3.i, i1 false
   br i1 %or.cond, label %_ZN4llvh12DenseMapBaseINS_8DenseMapIPN6hermes10BasicBlockENS_14DomTreeBuilder11SemiNCAInfoINS_17DominatorTreeBaseIS3_Lb0EEEE7InfoRecENS_12DenseMapInfoIS4_EENS_6detail12DenseMapPairIS4_SA_EEEES4_SA_SC_SF_E5clearEv.exit, label %if.end.i
 
 if.end.i:                                         ; preds = %_ZNSt6vectorIPN6hermes10BasicBlockESaIS2_EE13_M_assign_auxIPKS2_EEvT_S8_St20forward_iterator_tag.exit
-  %mul.i = shl i32 %3, 2
+  %mul.i = shl i32 %4, 2
   %NumBuckets.i.i.i = getelementptr inbounds %"struct.llvh::DomTreeBuilder::SemiNCAInfo", ptr %this, i64 0, i32 1, i32 3
-  %5 = load i32, ptr %NumBuckets.i.i.i, align 8
-  %cmp6.i = icmp ult i32 %mul.i, %5
-  %cmp9.i = icmp ugt i32 %5, 64
+  %6 = load i32, ptr %NumBuckets.i.i.i, align 8
+  %cmp6.i = icmp ult i32 %mul.i, %6
+  %cmp9.i = icmp ugt i32 %6, 64
   %or.cond.i = and i1 %cmp6.i, %cmp9.i
   br i1 %or.cond.i, label %if.then10.i, label %if.end11.i
 
@@ -20523,16 +20541,16 @@ if.then10.i:                                      ; preds = %if.end.i
   br label %_ZN4llvh12DenseMapBaseINS_8DenseMapIPN6hermes10BasicBlockENS_14DomTreeBuilder11SemiNCAInfoINS_17DominatorTreeBaseIS3_Lb0EEEE7InfoRecENS_12DenseMapInfoIS4_EENS_6detail12DenseMapPairIS4_SA_EEEES4_SA_SC_SF_E5clearEv.exit
 
 if.end11.i:                                       ; preds = %if.end.i
-  %6 = load ptr, ptr %NodeToInfo, align 8
-  %idx.ext.i.i = zext i32 %5 to i64
-  %add.ptr.i.i1 = getelementptr inbounds %"struct.llvh::detail::DenseMapPair.107", ptr %6, i64 %idx.ext.i.i
-  %cmp17.not13.i = icmp eq i32 %5, 0
+  %7 = load ptr, ptr %NodeToInfo, align 8
+  %idx.ext.i.i = zext i32 %6 to i64
+  %add.ptr.i.i1 = getelementptr inbounds %"struct.llvh::detail::DenseMapPair.107", ptr %7, i64 %idx.ext.i.i
+  %cmp17.not13.i = icmp eq i32 %6, 0
   br i1 %cmp17.not13.i, label %for.end.i, label %for.body.i
 
 for.body.i:                                       ; preds = %if.end11.i, %for.inc.i
-  %P.014.i = phi ptr [ %incdec.ptr.i, %for.inc.i ], [ %6, %if.end11.i ]
-  %7 = load ptr, ptr %P.014.i, align 8
-  %magicptr.i = ptrtoint ptr %7 to i64
+  %P.014.i = phi ptr [ %incdec.ptr.i, %for.inc.i ], [ %7, %if.end11.i ]
+  %8 = load ptr, ptr %P.014.i, align 8
+  %magicptr.i = ptrtoint ptr %8 to i64
   switch i64 %magicptr.i, label %if.then23.i [
     i64 -8, label %for.inc.i
     i64 -16, label %if.end25.i
@@ -20540,13 +20558,13 @@ for.body.i:                                       ; preds = %if.end11.i, %for.in
 
 if.then23.i:                                      ; preds = %for.body.i
   %ReverseChildren.i.i = getelementptr inbounds %"struct.std::pair.108", ptr %P.014.i, i64 0, i32 1, i32 5
-  %8 = load ptr, ptr %ReverseChildren.i.i, align 8
+  %9 = load ptr, ptr %ReverseChildren.i.i, align 8
   %add.ptr.i.i.i.i.i.i = getelementptr inbounds %"struct.std::pair.108", ptr %P.014.i, i64 0, i32 1, i32 5, i32 1
-  %cmp.i.i.i.i.i = icmp eq ptr %8, %add.ptr.i.i.i.i.i.i
+  %cmp.i.i.i.i.i = icmp eq ptr %9, %add.ptr.i.i.i.i.i.i
   br i1 %cmp.i.i.i.i.i, label %if.end25.i, label %if.then.i.i.i.i
 
 if.then.i.i.i.i:                                  ; preds = %if.then23.i
-  tail call void @free(ptr noundef %8) #13
+  tail call void @free(ptr noundef %9) #13
   br label %if.end25.i
 
 if.end25.i:                                       ; preds = %if.then.i.i.i.i, %if.then23.i, %for.body.i
@@ -24757,7 +24775,7 @@ if.then2.i39:                                     ; preds = %for.body.i20
   %sub.ptr.div.i.i.i.i.i.i43 = ashr exact i64 %sub.ptr.sub.i.i.i.i.i.i42, 3
   %.pre.i.i.i.i.i.i44 = sub nsw i64 0, %sub.ptr.div.i.i.i.i.i.i43
   %add.ptr.i.i.i.i.i.i45 = getelementptr inbounds ptr, ptr %add.ptr3.i40, i64 %.pre.i.i.i.i.i.i44
-  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %add.ptr.i.i.i.i.i.i45, ptr nonnull align 8 %__first, i64 %sub.ptr.sub.i.i.i.i.i.i42, i1 false)
+  tail call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %add.ptr.i.i.i.i.i.i45, ptr noundef nonnull align 8 dereferenceable(1) %__first, i64 %sub.ptr.sub.i.i.i.i.i.i42, i1 false)
   br label %for.inc.i29
 
 if.else.i26:                                      ; preds = %for.body.i20

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/protobuf/optimized/generated_message_tctable_gen.cc.ll b/bench/protobuf/optimized/generated_message_tctable_gen.cc.ll
index 2eda670e..4bbfef63 100644
--- a/bench/protobuf/optimized/generated_message_tctable_gen.cc.ll
+++ b/bench/protobuf/optimized/generated_message_tctable_gen.cc.ll
@@ -5620,22 +5620,22 @@ for.body.lr.ph:                                   ; preds = %entry
 
 for.body:                                         ; preds = %for.body.lr.ph, %for.inc
   %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.inc ]
-  %enum_values.sroa.0.061 = phi ptr [ null, %for.body.lr.ph ], [ %enum_values.sroa.0.1, %for.inc ]
-  %enum_values.sroa.14.060 = phi ptr [ null, %for.body.lr.ph ], [ %enum_values.sroa.14.1, %for.inc ]
-  %enum_values.sroa.26.059 = phi ptr [ null, %for.body.lr.ph ], [ %enum_values.sroa.26.1, %for.inc ]
+  %enum_values.sroa.0.074 = phi ptr [ null, %for.body.lr.ph ], [ %enum_values.sroa.0.1, %for.inc ]
+  %enum_values.sroa.14.073 = phi ptr [ null, %for.body.lr.ph ], [ %enum_values.sroa.14.1, %for.inc ]
+  %enum_values.sroa.26.072 = phi ptr [ null, %for.body.lr.ph ], [ %enum_values.sroa.26.1, %for.inc ]
   %5 = load ptr, ptr %values_.i, align 8
   %number_.i = getelementptr inbounds %"class.google::protobuf::EnumValueDescriptor", ptr %5, i64 %indvars.iv, i32 2
   %6 = load i32, ptr %number_.i, align 4
-  %cmp.not.i.i = icmp eq ptr %enum_values.sroa.14.060, %enum_values.sroa.26.059
+  %cmp.not.i.i = icmp eq ptr %enum_values.sroa.14.073, %enum_values.sroa.26.072
   br i1 %cmp.not.i.i, label %if.else.i.i, label %if.then.i.i
 
 if.then.i.i:                                      ; preds = %for.body
-  store i32 %6, ptr %enum_values.sroa.14.060, align 4
+  store i32 %6, ptr %enum_values.sroa.14.073, align 4
   br label %for.inc
 
 if.else.i.i:                                      ; preds = %for.body
-  %sub.ptr.lhs.cast.i.i.i.i.i = ptrtoint ptr %enum_values.sroa.14.060 to i64
-  %sub.ptr.rhs.cast.i.i.i.i.i = ptrtoint ptr %enum_values.sroa.0.061 to i64
+  %sub.ptr.lhs.cast.i.i.i.i.i = ptrtoint ptr %enum_values.sroa.14.073 to i64
+  %sub.ptr.rhs.cast.i.i.i.i.i = ptrtoint ptr %enum_values.sroa.0.074 to i64
   %sub.ptr.sub.i.i.i.i.i = sub i64 %sub.ptr.lhs.cast.i.i.i.i.i, %sub.ptr.rhs.cast.i.i.i.i.i
   %cmp.i.i.i.i = icmp eq i64 %sub.ptr.sub.i.i.i.i.i, 9223372036854775804
   br i1 %cmp.i.i.i.i, label %if.then.i.i.i.i, label %_ZNKSt6vectorIiSaIiEE12_M_check_lenEmPKc.exit.i.i.i
@@ -5671,15 +5671,15 @@ _ZNSt12_Vector_baseIiSaIiEE11_M_allocateEm.exit.i.i.i: ; preds = %_ZNSt16allocat
   br i1 %cmp.i.i.i11.i.i.i, label %if.then.i.i.i12.i.i.i, label %_ZNSt6vectorIiSaIiEE11_S_relocateEPiS2_S2_RS0_.exit20.i.i.i
 
 if.then.i.i.i12.i.i.i:                            ; preds = %_ZNSt12_Vector_baseIiSaIiEE11_M_allocateEm.exit.i.i.i
-  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 4 %cond.i10.i.i.i, ptr align 4 %enum_values.sroa.0.061, i64 %sub.ptr.sub.i.i.i.i.i, i1 false)
+  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 4 %cond.i10.i.i.i, ptr align 4 %enum_values.sroa.0.074, i64 %sub.ptr.sub.i.i.i.i.i, i1 false)
   br label %_ZNSt6vectorIiSaIiEE11_S_relocateEPiS2_S2_RS0_.exit20.i.i.i
 
 _ZNSt6vectorIiSaIiEE11_S_relocateEPiS2_S2_RS0_.exit20.i.i.i: ; preds = %if.then.i.i.i12.i.i.i, %_ZNSt12_Vector_baseIiSaIiEE11_M_allocateEm.exit.i.i.i
-  %tobool.not.i.i.i.i = icmp eq ptr %enum_values.sroa.0.061, null
+  %tobool.not.i.i.i.i = icmp eq ptr %enum_values.sroa.0.074, null
   br i1 %tobool.not.i.i.i.i, label %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i, label %if.then.i21.i.i.i
 
 if.then.i21.i.i.i:                                ; preds = %_ZNSt6vectorIiSaIiEE11_S_relocateEPiS2_S2_RS0_.exit20.i.i.i
-  tail call void @_ZdlPv(ptr noundef nonnull %enum_values.sroa.0.061) #20
+  tail call void @_ZdlPv(ptr noundef nonnull %enum_values.sroa.0.074) #20
   br label %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i
 
 _ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i: ; preds = %if.then.i21.i.i.i, %_ZNSt6vectorIiSaIiEE11_S_relocateEPiS2_S2_RS0_.exit20.i.i.i
@@ -5687,9 +5687,9 @@ _ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS
   br label %for.inc
 
 for.inc:                                          ; preds = %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i, %if.then.i.i
-  %enum_values.sroa.26.1 = phi ptr [ %add.ptr19.i.i.i, %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i ], [ %enum_values.sroa.26.059, %if.then.i.i ]
-  %add.ptr.i.i.i.pn = phi ptr [ %add.ptr.i.i.i, %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i ], [ %enum_values.sroa.14.060, %if.then.i.i ]
-  %enum_values.sroa.0.1 = phi ptr [ %cond.i10.i.i.i, %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i ], [ %enum_values.sroa.0.061, %if.then.i.i ]
+  %enum_values.sroa.26.1 = phi ptr [ %add.ptr19.i.i.i, %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i ], [ %enum_values.sroa.26.072, %if.then.i.i ]
+  %add.ptr.i.i.i.pn = phi ptr [ %add.ptr.i.i.i, %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i ], [ %enum_values.sroa.14.073, %if.then.i.i ]
+  %enum_values.sroa.0.1 = phi ptr [ %cond.i10.i.i.i, %_ZNSt6vectorIiSaIiEE17_M_realloc_insertIJiEEEvN9__gnu_cxx17__normal_iteratorIPiS1_EEDpOT_.exit.i.i ], [ %enum_values.sroa.0.074, %if.then.i.i ]
   %enum_values.sroa.14.1 = getelementptr inbounds i32, ptr %add.ptr.i.i.i.pn, i64 1
   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
   %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
@@ -5701,19 +5701,19 @@ lpad11.loopexit:                                  ; preds = %_ZNSt16allocator_tr
   br label %lpad11
 
 lpad11.loopexit.split-lp:                         ; preds = %if.then.i.i.i.i, %for.end
-  %enum_values.sroa.0.055 = phi ptr [ %enum_values.sroa.0.061, %if.then.i.i.i.i ], [ %enum_values.sroa.0.1, %for.end ]
+  %enum_values.sroa.0.068 = phi ptr [ %enum_values.sroa.0.074, %if.then.i.i.i.i ], [ %enum_values.sroa.0.1, %for.end ]
   %lpad.loopexit.split-lp = landingpad { ptr, i32 }
           cleanup
   br label %lpad11
 
 lpad11:                                           ; preds = %lpad11.loopexit.split-lp, %lpad11.loopexit
-  %enum_values.sroa.0.054 = phi ptr [ %enum_values.sroa.0.061, %lpad11.loopexit ], [ %enum_values.sroa.0.055, %lpad11.loopexit.split-lp ]
+  %enum_values.sroa.0.067 = phi ptr [ %enum_values.sroa.0.074, %lpad11.loopexit ], [ %enum_values.sroa.0.068, %lpad11.loopexit.split-lp ]
   %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %lpad11.loopexit ], [ %lpad.loopexit.split-lp, %lpad11.loopexit.split-lp ]
-  %tobool.not.i.i.i = icmp eq ptr %enum_values.sroa.0.054, null
+  %tobool.not.i.i.i = icmp eq ptr %enum_values.sroa.0.067, null
   br i1 %tobool.not.i.i.i, label %_ZNSt6vectorIiSaIiEED2Ev.exit, label %if.then.i.i.i
 
 if.then.i.i.i:                                    ; preds = %lpad11
-  tail call void @_ZdlPv(ptr noundef nonnull %enum_values.sroa.0.054) #20
+  tail call void @_ZdlPv(ptr noundef nonnull %enum_values.sroa.0.067) #20
   br label %_ZNSt6vectorIiSaIiEED2Ev.exit
 
 _ZNSt6vectorIiSaIiEED2Ev.exit:                    ; preds = %lpad11, %if.then.i.i.i
@@ -5725,12 +5725,20 @@ for.end:                                          ; preds = %for.inc
 
 invoke.cont27:                                    ; preds = %for.end
   %cmp.i.i.i.i10 = icmp eq ptr %enum_values.sroa.0.1, %enum_values.sroa.14.1
-  br i1 %cmp.i.i.i.i10, label %invoke.cont34, label %while.cond.i.i.i
+  br i1 %cmp.i.i.i.i10, label %invoke.cont34.thread81, label %while.cond.i.i.i
+
+invoke.cont34.thread81:                           ; preds = %invoke.cont27
+  %sub.ptr.rhs.cast.i.i84 = ptrtoint ptr %enum_values.sroa.0.1 to i64
+  br label %invoke.cont40
 
 while.cond.i.i.i:                                 ; preds = %invoke.cont27, %while.body.i.i.i
   %__first.sroa.0.0.i.i.i = phi ptr [ %incdec.ptr.i.i.i.i, %while.body.i.i.i ], [ %enum_values.sroa.0.1, %invoke.cont27 ]
   %cmp.i3.not.i.i.i = icmp eq ptr %__first.sroa.0.0.i.i.i, %add.ptr.i.i.i.pn
-  br i1 %cmp.i3.not.i.i.i, label %invoke.cont34, label %while.body.i.i.i
+  br i1 %cmp.i3.not.i.i.i, label %invoke.cont34.thread, label %while.body.i.i.i
+
+invoke.cont34.thread:                             ; preds = %while.cond.i.i.i
+  %sub.ptr.rhs.cast.i.i53 = ptrtoint ptr %enum_values.sroa.0.1 to i64
+  br label %invoke.cont40
 
 while.body.i.i.i:                                 ; preds = %while.cond.i.i.i
   %incdec.ptr.i.i.i.i = getelementptr inbounds i32, ptr %__first.sroa.0.0.i.i.i, i64 1
@@ -5742,7 +5750,7 @@ while.body.i.i.i:                                 ; preds = %while.cond.i.i.i
 if.end.i.i:                                       ; preds = %while.body.i.i.i
   %incdec.ptr.i217.i.i = getelementptr inbounds i32, ptr %__first.sroa.0.0.i.i.i, i64 2
   %cmp.i3.not18.i.i = icmp eq ptr %incdec.ptr.i217.i.i, %enum_values.sroa.14.1
-  br i1 %cmp.i3.not18.i.i, label %while.end.i.i, label %while.body.i.i
+  br i1 %cmp.i3.not18.i.i, label %invoke.cont34, label %while.body.i.i
 
 while.body.i.i:                                   ; preds = %if.end.i.i, %if.end20.i.i
   %9 = phi i32 [ %10, %if.end20.i.i ], [ %7, %if.end.i.i ]
@@ -5761,16 +5769,12 @@ if.end20.i.i:                                     ; preds = %if.then16.i.i, %whi
   %__dest.sroa.0.1.i.i = phi ptr [ %__dest.sroa.0.019.i.i, %while.body.i.i ], [ %incdec.ptr.i5.i.i, %if.then16.i.i ]
   %incdec.ptr.i2.i.i = getelementptr inbounds i32, ptr %incdec.ptr.i220.i.i, i64 1
   %cmp.i3.not.i.i = icmp eq ptr %incdec.ptr.i220.i.i, %add.ptr.i.i.i.pn
-  br i1 %cmp.i3.not.i.i, label %while.end.i.i, label %while.body.i.i, !llvm.loop !31
+  br i1 %cmp.i3.not.i.i, label %invoke.cont34, label %while.body.i.i, !llvm.loop !31
 
-while.end.i.i:                                    ; preds = %if.end20.i.i, %if.end.i.i
+invoke.cont34:                                    ; preds = %if.end20.i.i, %if.end.i.i
   %__dest.sroa.0.0.lcssa.i.i = phi ptr [ %__first.sroa.0.0.i.i.i, %if.end.i.i ], [ %__dest.sroa.0.1.i.i, %if.end20.i.i ]
   %incdec.ptr.i6.i.i = getelementptr inbounds i32, ptr %__dest.sroa.0.0.lcssa.i.i, i64 1
-  br label %invoke.cont34
-
-invoke.cont34:                                    ; preds = %while.cond.i.i.i, %while.end.i.i, %invoke.cont27
-  %retval.sroa.0.0.in.sroa.speculated.i.i = phi ptr [ %incdec.ptr.i6.i.i, %while.end.i.i ], [ %enum_values.sroa.14.1, %invoke.cont27 ], [ %enum_values.sroa.14.1, %while.cond.i.i.i ]
-  %sub.ptr.lhs.cast.i.i = ptrtoint ptr %retval.sroa.0.0.in.sroa.speculated.i.i to i64
+  %sub.ptr.lhs.cast.i.i = ptrtoint ptr %incdec.ptr.i6.i.i to i64
   %sub.ptr.rhs.cast.i.i = ptrtoint ptr %enum_values.sroa.0.1 to i64
   %sub.ptr.sub.i.i = sub i64 %sub.ptr.lhs.cast.i.i, %sub.ptr.rhs.cast.i.i
   %sub.ptr.div.i.i = ashr exact i64 %sub.ptr.sub.i.i, 2
@@ -5779,7 +5783,7 @@ invoke.cont34:                                    ; preds = %while.cond.i.i.i, %
   %sub.ptr.sub.i3.i = sub i64 %sub.ptr.lhs.cast.i1.i, %sub.ptr.rhs.cast.i.i
   %sub.ptr.div.i4.i = ashr exact i64 %sub.ptr.sub.i3.i, 2
   %add.ptr.i5.i = getelementptr inbounds i32, ptr %enum_values.sroa.0.1, i64 %sub.ptr.div.i4.i
-  %cmp.i.not.i.i = icmp eq i64 %sub.ptr.div.i.i, %sub.ptr.div.i4.i
+  %cmp.i.not.i.i = icmp eq ptr %__dest.sroa.0.0.lcssa.i.i, %add.ptr.i.i.i.pn
   br i1 %cmp.i.not.i.i, label %invoke.cont40, label %if.then.i.i11
 
 if.then.i.i11:                                    ; preds = %invoke.cont34
@@ -5798,8 +5802,9 @@ if.end.i.i12:                                     ; preds = %if.then.i.i11, %_ZS
   %add.ptr.i6.i = getelementptr inbounds i32, ptr %add.ptr.i.i, i64 %sub.ptr.sub.i.i.i.pre-phi
   br label %invoke.cont40
 
-invoke.cont40:                                    ; preds = %if.end.i.i12, %invoke.cont34
-  %enum_values.sroa.14.2 = phi ptr [ %enum_values.sroa.14.1, %invoke.cont34 ], [ %add.ptr.i6.i, %if.end.i.i12 ]
+invoke.cont40:                                    ; preds = %invoke.cont34.thread81, %if.end.i.i12, %invoke.cont34, %invoke.cont34.thread
+  %sub.ptr.rhs.cast.i.i62 = phi i64 [ %sub.ptr.rhs.cast.i.i, %invoke.cont34 ], [ %sub.ptr.rhs.cast.i.i53, %invoke.cont34.thread ], [ %sub.ptr.rhs.cast.i.i, %if.end.i.i12 ], [ %sub.ptr.rhs.cast.i.i84, %invoke.cont34.thread81 ]
+  %enum_values.sroa.14.2 = phi ptr [ %enum_values.sroa.14.1, %invoke.cont34 ], [ %enum_values.sroa.14.1, %invoke.cont34.thread ], [ %add.ptr.i6.i, %if.end.i.i12 ], [ %enum_values.sroa.14.1, %invoke.cont34.thread81 ]
   %12 = load i32, ptr %enum_values.sroa.0.1, align 4
   %13 = add i32 %12, -32768
   %or.cond = icmp ult i32 %13, -65536
@@ -5807,7 +5812,7 @@ invoke.cont40:                                    ; preds = %if.end.i.i12, %invo
 
 land.lhs.true50:                                  ; preds = %invoke.cont40
   %sub.ptr.lhs.cast.i = ptrtoint ptr %enum_values.sroa.14.2 to i64
-  %sub.ptr.sub.i = sub i64 %sub.ptr.lhs.cast.i, %sub.ptr.rhs.cast.i.i
+  %sub.ptr.sub.i = sub i64 %sub.ptr.lhs.cast.i, %sub.ptr.rhs.cast.i.i62
   %sub.ptr.div.i = ashr exact i64 %sub.ptr.sub.i, 2
   %cmp54.not = icmp ugt i64 %sub.ptr.div.i, 65535
   br i1 %cmp54.not, label %_ZNSt6vectorIiSaIiEED2Ev.exit29, label %land.lhs.true55
@@ -6028,7 +6033,7 @@ _ZSt13move_backwardIN9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEES6_ET0_T
   %sub.ptr.div.i.i.i.i.i.i34.i = ashr exact i64 %sub.ptr.sub.i.i.i.i.i.i33.i, 2
   %.pre.i.i.i.i.i.i35.i = sub nsw i64 0, %sub.ptr.div.i.i.i.i.i.i34.i
   %add.ptr.i.i.i.i.i.i36.i = getelementptr inbounds i32, ptr %add.ptr.i3.i31.i, i64 %.pre.i.i.i.i.i.i35.i
-  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 4 %add.ptr.i.i.i.i.i.i36.i, ptr nonnull align 4 %__first.coerce, i64 %sub.ptr.sub.i.i.i.i.i.i33.i, i1 false)
+  tail call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %add.ptr.i.i.i.i.i.i36.i, ptr noundef nonnull align 4 dereferenceable(1) %__first.coerce, i64 %sub.ptr.sub.i.i.i.i.i.i33.i, i1 false)
   br label %for.inc.i21.i
 
 if.else.i19.i:                                    ; preds = %for.body.i15.i

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/re2/optimized/dfa.cc.ll b/bench/re2/optimized/dfa.cc.ll
index 5a78c1a1..35309395 100644
--- a/bench/re2/optimized/dfa.cc.ll
+++ b/bench/re2/optimized/dfa.cc.ll
@@ -1616,61 +1616,86 @@ for.body.lr.ph.i:                                 ; preds = %while.body.i
   %11 = zext i16 %10 to i32
   %12 = load ptr, ptr %8, align 8
   %13 = load i32, ptr %ninst_2.i.i.i.i.i.i.i, align 8
-  %conv3.i.i.i.i.i.i.i = sext i32 %13 to i64
-  %add.ptr.i2.idx.i.i.i.i.i.i.i.i.i = shl nsw i64 %conv3.i.i.i.i.i.i.i, 2
-  br label %for.body.i
-
-for.body.i:                                       ; preds = %for.inc.i, %for.body.lr.ph.i
-  %__begin5.sroa.0.027.i = phi i32 [ %11, %for.body.lr.ph.i ], [ %and.i9.i, %for.inc.i ]
-  %14 = tail call noundef i32 @llvm.cttz.i32(i32 %__begin5.sroa.0.027.i, i1 true), !range !5
-  %conv.i = zext nneg i32 %14 to i64
+  %.fr = freeze i32 %13
+  %tobool.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %.fr, 0
+  br i1 %tobool.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, label %for.body.i.us, label %for.body.i
+
+for.body.i.us:                                    ; preds = %for.body.lr.ph.i, %for.inc.i.us
+  %__begin5.sroa.0.027.i.us = phi i32 [ %and.i9.i.us, %for.inc.i.us ], [ %11, %for.body.lr.ph.i ]
+  %14 = tail call noundef i32 @llvm.cttz.i32(i32 %__begin5.sroa.0.027.i.us, i1 true), !range !5
+  %conv.i.us = zext nneg i32 %14 to i64
+  %add.i.i.us = add i64 %seq.sroa.4.0.i, %conv.i.us
+  %and.i.i.us = and i64 %add.i.i.us, %4
+  %add.ptr14.i.us = getelementptr inbounds ptr, ptr %7, i64 %and.i.i.us
+  %15 = load ptr, ptr %add.ptr14.i.us, align 8
+  %cmp.i.i.i.i.i.i.i.us = icmp eq ptr %15, %8
+  br i1 %cmp.i.i.i.i.i.i.i.us, label %if.then.i, label %lor.rhs.i.i.i.i.i.i.i.us
+
+lor.rhs.i.i.i.i.i.i.i.us:                         ; preds = %for.body.i.us
+  %ninst_.i.i.i.i.i.i.i.us = getelementptr inbounds %"struct.re2::DFA::State", ptr %15, i64 0, i32 1
+  %16 = load i32, ptr %ninst_.i.i.i.i.i.i.i.us, align 8
+  %flag_.i.i.i.i.i.i.i.us = getelementptr inbounds %"struct.re2::DFA::State", ptr %15, i64 0, i32 2
+  %17 = load i32, ptr %flag_.i.i.i.i.i.i.i.us, align 4
+  %18 = load i32, ptr %flag_4.i.i.i.i.i.i.i, align 4
+  %cmp5.i.i.i.i.i.i.i.us = icmp eq i32 %17, %18
+  %cmp.i.i.i.i.i.i.i.i.i.i.i.i.us = icmp eq i32 %16, 0
+  %or.cond = select i1 %cmp5.i.i.i.i.i.i.i.us, i1 %cmp.i.i.i.i.i.i.i.i.i.i.i.i.us, i1 false
+  br i1 %or.cond, label %if.then.i, label %for.inc.i.us
+
+for.inc.i.us:                                     ; preds = %lor.rhs.i.i.i.i.i.i.i.us
+  %sub.i.i.us = add nsw i32 %__begin5.sroa.0.027.i.us, -1
+  %and.i9.i.us = and i32 %sub.i.i.us, %__begin5.sroa.0.027.i.us
+  %cmp.i.not.i.us = icmp eq i32 %and.i9.i.us, 0
+  br i1 %cmp.i.not.i.us, label %for.end.i, label %for.body.i.us
+
+for.body.i:                                       ; preds = %for.body.lr.ph.i, %for.inc.i
+  %__begin5.sroa.0.027.i = phi i32 [ %and.i9.i, %for.inc.i ], [ %11, %for.body.lr.ph.i ]
+  %19 = tail call noundef i32 @llvm.cttz.i32(i32 %__begin5.sroa.0.027.i, i1 true), !range !5
+  %conv.i = zext nneg i32 %19 to i64
   %add.i.i = add i64 %seq.sroa.4.0.i, %conv.i
   %and.i.i = and i64 %add.i.i, %4
   %add.ptr14.i = getelementptr inbounds ptr, ptr %7, i64 %and.i.i
-  %15 = load ptr, ptr %add.ptr14.i, align 8
-  %16 = load ptr, ptr %15, align 8
-  %ninst_.i.i.i.i.i.i.i = getelementptr inbounds %"struct.re2::DFA::State", ptr %15, i64 0, i32 1
-  %17 = load i32, ptr %ninst_.i.i.i.i.i.i.i, align 8
-  %cmp.i.i.i.i.i.i.i = icmp eq ptr %15, %8
+  %20 = load ptr, ptr %add.ptr14.i, align 8
+  %21 = load ptr, ptr %20, align 8
+  %ninst_.i.i.i.i.i.i.i = getelementptr inbounds %"struct.re2::DFA::State", ptr %20, i64 0, i32 1
+  %22 = load i32, ptr %ninst_.i.i.i.i.i.i.i, align 8
+  %conv.i.i.i.i.i.i.i = sext i32 %22 to i64
+  %cmp.i.i.i.i.i.i.i = icmp eq ptr %20, %8
   br i1 %cmp.i.i.i.i.i.i.i, label %if.then.i, label %lor.rhs.i.i.i.i.i.i.i
 
 lor.rhs.i.i.i.i.i.i.i:                            ; preds = %for.body.i
-  %conv.i.i.i.i.i.i.i = sext i32 %17 to i64
-  %flag_.i.i.i.i.i.i.i = getelementptr inbounds %"struct.re2::DFA::State", ptr %15, i64 0, i32 2
-  %18 = load i32, ptr %flag_.i.i.i.i.i.i.i, align 4
-  %19 = load i32, ptr %flag_4.i.i.i.i.i.i.i, align 4
-  %cmp5.i.i.i.i.i.i.i = icmp eq i32 %18, %19
-  %add.ptr.i.idx.i.i.i.i.i.i.i.i.i = shl nsw i64 %conv.i.i.i.i.i.i.i, 2
-  %cmp.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i64 %add.ptr.i.idx.i.i.i.i.i.i.i.i.i, %add.ptr.i2.idx.i.i.i.i.i.i.i.i.i
-  %or.cond.i = select i1 %cmp5.i.i.i.i.i.i.i, i1 %cmp.i.i.i.i.i.i.i.i.i.i.i.i, i1 false
-  br i1 %or.cond.i, label %land.rhs.i.i.i.i.i.i.i.i.i.i.i.i, label %for.inc.i
+  %flag_.i.i.i.i.i.i.i = getelementptr inbounds %"struct.re2::DFA::State", ptr %20, i64 0, i32 2
+  %23 = load i32, ptr %flag_.i.i.i.i.i.i.i, align 4
+  %24 = load i32, ptr %flag_4.i.i.i.i.i.i.i, align 4
+  %cmp5.i.i.i.i.i.i.i = icmp eq i32 %23, %24
+  %cmp.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %22, %.fr
+  %or.cond16 = select i1 %cmp5.i.i.i.i.i.i.i, i1 %cmp.i.i.i.i.i.i.i.i.i.i.i.i, i1 false
+  br i1 %or.cond16, label %land.rhs.i.i.i.i.i.i.i.i.i.i.i.i, label %for.inc.i
 
 land.rhs.i.i.i.i.i.i.i.i.i.i.i.i:                 ; preds = %lor.rhs.i.i.i.i.i.i.i
-  %tobool.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %17, 0
-  br i1 %tobool.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, label %if.then.i, label %_ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit.i
-
-_ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit.i: ; preds = %land.rhs.i.i.i.i.i.i.i.i.i.i.i.i
-  %bcmp.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = tail call i32 @bcmp(ptr %16, ptr %12, i64 %add.ptr.i2.idx.i.i.i.i.i.i.i.i.i)
+  %add.ptr.i.idx.i.i.i.i.i.i.i.i.i = shl nsw i64 %conv.i.i.i.i.i.i.i, 2
+  %bcmp.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = tail call i32 @bcmp(ptr %21, ptr %12, i64 %add.ptr.i.idx.i.i.i.i.i.i.i.i.i)
   %tobool1.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %bcmp.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, 0
   br i1 %tobool1.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, label %if.then.i, label %for.inc.i
 
-if.then.i:                                        ; preds = %_ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit.i, %land.rhs.i.i.i.i.i.i.i.i.i.i.i.i, %for.body.i
-  %add.ptr14.i.le = getelementptr inbounds ptr, ptr %7, i64 %and.i.i
-  %add.ptr.i.i = getelementptr inbounds i8, ptr %3, i64 %and.i.i
+if.then.i:                                        ; preds = %for.body.i, %land.rhs.i.i.i.i.i.i.i.i.i.i.i.i, %lor.rhs.i.i.i.i.i.i.i.us, %for.body.i.us
+  %.us-phi = phi i64 [ %and.i.i.us, %for.body.i.us ], [ %and.i.i.us, %lor.rhs.i.i.i.i.i.i.i.us ], [ %and.i.i, %land.rhs.i.i.i.i.i.i.i.i.i.i.i.i ], [ %and.i.i, %for.body.i ]
+  %add.ptr14.i.le = getelementptr inbounds ptr, ptr %7, i64 %.us-phi
+  %add.ptr.i.i = getelementptr inbounds i8, ptr %3, i64 %.us-phi
   %.fca.0.insert.i.i = insertvalue { ptr, ptr } poison, ptr %add.ptr.i.i, 0
   %.fca.1.insert.i.i = insertvalue { ptr, ptr } %.fca.0.insert.i.i, ptr %add.ptr14.i.le, 1
   br label %_ZN4absl7debian218container_internal12raw_hash_setINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEENS5_9StateHashENS5_10StateEqualESaIS7_EE4findIS7_EENSC_8iteratorERKS7_m.exit
 
-for.inc.i:                                        ; preds = %_ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit.i, %lor.rhs.i.i.i.i.i.i.i
+for.inc.i:                                        ; preds = %land.rhs.i.i.i.i.i.i.i.i.i.i.i.i, %lor.rhs.i.i.i.i.i.i.i
   %sub.i.i = add nsw i32 %__begin5.sroa.0.027.i, -1
   %and.i9.i = and i32 %sub.i.i, %__begin5.sroa.0.027.i
   %cmp.i.not.i = icmp eq i32 %and.i9.i, 0
   br i1 %cmp.i.not.i, label %for.end.i, label %for.body.i
 
-for.end.i:                                        ; preds = %for.inc.i, %while.body.i
+for.end.i:                                        ; preds = %for.inc.i, %for.inc.i.us, %while.body.i
   %cmp.i.i.i10.i = icmp eq <16 x i8> %9, <i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128>
-  %20 = bitcast <16 x i1> %cmp.i.i.i10.i to i16
-  %cmp.i11.not.i = icmp eq i16 %20, 0
+  %25 = bitcast <16 x i1> %cmp.i.i.i10.i to i16
+  %cmp.i11.not.i = icmp eq i16 %25, 0
   br i1 %cmp.i11.not.i, label %if.end29.i, label %_ZN4absl7debian218container_internal12raw_hash_setINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEENS5_9StateHashENS5_10StateEqualESaIS7_EE4findIS7_EENSC_8iteratorERKS7_m.exit
 
 if.end29.i:                                       ; preds = %for.end.i
@@ -12523,8 +12548,7 @@ for.body.lr.ph:                                   ; preds = %while.body
   %11 = zext i16 %10 to i32
   %12 = load ptr, ptr %8, align 8
   %13 = load i32, ptr %ninst_2.i.i.i.i.i.i, align 8
-  %conv3.i.i.i.i.i.i = sext i32 %13 to i64
-  %add.ptr.i2.idx.i.i.i.i.i.i.i.i = shl nsw i64 %conv3.i.i.i.i.i.i, 2
+  %tobool.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %13, 0
   br label %for.body
 
 for.body:                                         ; preds = %for.body.lr.ph, %for.inc
@@ -12538,30 +12562,31 @@ for.body:                                         ; preds = %for.body.lr.ph, %fo
   %16 = load ptr, ptr %15, align 8
   %ninst_.i.i.i.i.i.i8 = getelementptr inbounds %"struct.re2::DFA::State", ptr %15, i64 0, i32 1
   %17 = load i32, ptr %ninst_.i.i.i.i.i.i8, align 8
+  %conv.i.i.i.i.i.i9 = sext i32 %17 to i64
   %cmp.i.i.i.i.i.i = icmp eq ptr %15, %8
   br i1 %cmp.i.i.i.i.i.i, label %return, label %lor.rhs.i.i.i.i.i.i
 
 lor.rhs.i.i.i.i.i.i:                              ; preds = %for.body
-  %conv.i.i.i.i.i.i9 = sext i32 %17 to i64
   %flag_.i.i.i.i.i.i10 = getelementptr inbounds %"struct.re2::DFA::State", ptr %15, i64 0, i32 2
   %18 = load i32, ptr %flag_.i.i.i.i.i.i10, align 4
   %19 = load i32, ptr %flag_4.i.i.i.i.i.i, align 4
   %cmp5.i.i.i.i.i.i = icmp eq i32 %18, %19
+  br i1 %cmp5.i.i.i.i.i.i, label %land.rhs.i.i.i.i.i.i, label %for.inc
+
+land.rhs.i.i.i.i.i.i:                             ; preds = %lor.rhs.i.i.i.i.i.i
   %add.ptr.i.idx.i.i.i.i.i.i.i.i = shl nsw i64 %conv.i.i.i.i.i.i9, 2
-  %cmp.i.i.i.i.i.i.i.i.i.i.i = icmp eq i64 %add.ptr.i.idx.i.i.i.i.i.i.i.i, %add.ptr.i2.idx.i.i.i.i.i.i.i.i
-  %or.cond = select i1 %cmp5.i.i.i.i.i.i, i1 %cmp.i.i.i.i.i.i.i.i.i.i.i, i1 false
-  br i1 %or.cond, label %land.rhs.i.i.i.i.i.i.i.i.i.i.i, label %for.inc
+  %cmp.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %17, %13
+  br i1 %cmp.i.i.i.i.i.i.i.i.i.i.i, label %land.rhs.i.i.i.i.i.i.i.i.i.i.i, label %for.inc
 
-land.rhs.i.i.i.i.i.i.i.i.i.i.i:                   ; preds = %lor.rhs.i.i.i.i.i.i
-  %tobool.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %17, 0
+land.rhs.i.i.i.i.i.i.i.i.i.i.i:                   ; preds = %land.rhs.i.i.i.i.i.i
   br i1 %tobool.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, label %return, label %_ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit
 
 _ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit: ; preds = %land.rhs.i.i.i.i.i.i.i.i.i.i.i
-  %bcmp.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = tail call i32 @bcmp(ptr %16, ptr %12, i64 %add.ptr.i2.idx.i.i.i.i.i.i.i.i)
+  %bcmp.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = tail call i32 @bcmp(ptr %16, ptr %12, i64 %add.ptr.i.idx.i.i.i.i.i.i.i.i)
   %tobool1.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i = icmp eq i32 %bcmp.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, 0
   br i1 %tobool1.not.i.i.i.i.i.i.i.i.i.i.i.i.i.i.i, label %return, label %for.inc
 
-for.inc:                                          ; preds = %lor.rhs.i.i.i.i.i.i, %_ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit
+for.inc:                                          ; preds = %land.rhs.i.i.i.i.i.i, %lor.rhs.i.i.i.i.i.i, %_ZN4absl7debian218container_internal18hash_policy_traitsINS1_17FlatHashSetPolicyIPN3re23DFA5StateEEEvE5applyINS1_12raw_hash_setIS8_NS5_9StateHashENS5_10StateEqualESaIS7_EE12EqualElementIS7_EEJRS7_ES8_EEDTclsrT1_5applyclsr3stdE7forwardIT_Efp_Espclsr3stdE7forwardIT0_Efp0_EEEOSK_DpOSL_.exit
   %sub.i = add nsw i32 %__begin0.sroa.0.032, -1
   %and.i14 = and i32 %sub.i, %__begin0.sroa.0.032
   %cmp.i.not = icmp eq i32 %and.i14, 0

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/rocksdb/optimized/compaction_picker_level.cc.ll b/bench/rocksdb/optimized/compaction_picker_level.cc.ll
index af392124..ff12aa91 100644
--- a/bench/rocksdb/optimized/compaction_picker_level.cc.ll
+++ b/bench/rocksdb/optimized/compaction_picker_level.cc.ll
@@ -1366,8 +1366,7 @@ if.end170.i.i.i:                                  ; preds = %for.end167.i.i.i
   %sub.ptr.lhs.cast.i14.i = ptrtoint ptr %169 to i64
   %sub.ptr.rhs.cast.i15.i = ptrtoint ptr %170 to i64
   %sub.ptr.sub.i16.i = sub i64 %sub.ptr.lhs.cast.i14.i, %sub.ptr.rhs.cast.i15.i
-  %sub.ptr.div.i17.i = ashr exact i64 %sub.ptr.sub.i16.i, 3
-  %cmp3.i = icmp ugt i64 %sub.ptr.div.i.i, %sub.ptr.div.i17.i
+  %cmp3.i = icmp ugt i64 %sub.ptr.sub.i.i, %sub.ptr.sub.i16.i
   br i1 %cmp3.i, label %cond.true.i.i.i, label %if.else.i
 
 cond.true.i.i.i:                                  ; preds = %if.end170.i.i.i
@@ -1411,8 +1410,7 @@ if.else.i:                                        ; preds = %if.end170.i.i.i
   %171 = load ptr, ptr %_M_finish.i.i.i10.i.i, align 8
   %sub.ptr.lhs.cast.i20.i = ptrtoint ptr %171 to i64
   %sub.ptr.sub.i22.i = sub i64 %sub.ptr.lhs.cast.i20.i, %sub.ptr.rhs.cast.i15.i
-  %sub.ptr.div.i23.i = ashr exact i64 %sub.ptr.sub.i22.i, 3
-  %cmp26.not.i = icmp ult i64 %sub.ptr.div.i23.i, %sub.ptr.div.i.i
+  %cmp26.not.i = icmp ult i64 %sub.ptr.sub.i22.i, %sub.ptr.sub.i.i
   br i1 %cmp26.not.i, label %if.else49.i, label %if.then27.i
 
 if.then27.i:                                      ; preds = %if.else.i
@@ -3105,6 +3103,7 @@ declare void @_ZN7rocksdb16CompactionPicker28PickFilesMarkedForCompactionERKNSt7
 ; Function Attrs: mustprogress uwtable
 define internal fastcc void @_ZN7rocksdb12_GLOBAL__N_122LevelCompactionBuilder17PickFileToCompactERKNS_10autovectorISt4pairIiPNS_12FileMetaDataEELm8EEEb(ptr noundef nonnull align 8 dereferenceable(256) %this, ptr nocapture noundef nonnull readonly align 8 dereferenceable(168) %level_files, i1 noundef zeroext %compact_to_next_level) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
 entry:
+  %ref.tmp.sroa.0 = alloca ptr, align 8
   %0 = load i64, ptr %level_files, align 8, !noalias !25
   %vect_.i.i = getelementptr inbounds %"class.rocksdb::autovector.45", ptr %level_files, i64 0, i32 3
   %_M_finish.i.i.i = getelementptr inbounds %"class.rocksdb::autovector.45", ptr %level_files, i64 0, i32 3, i32 0, i32 0, i32 0, i32 1
@@ -3187,20 +3186,24 @@ if.end23:                                         ; preds = %lor.lhs.false.threa
   store i32 %storemerge, ptr %output_level_22, align 4
   %second = getelementptr inbounds %"struct.std::pair", ptr %retval.0.i.i, i64 0, i32 1
   %14 = load ptr, ptr %second, align 8
+  store ptr %14, ptr %ref.tmp.sroa.0, align 8
   %15 = load ptr, ptr %_M_end_of_storage.i.i, align 8
   %16 = load ptr, ptr %files, align 8
-  %cmp.i = icmp eq ptr %15, %16
+  %sub.ptr.lhs.cast.i.i = ptrtoint ptr %15 to i64
+  %sub.ptr.rhs.cast.i.i = ptrtoint ptr %16 to i64
+  %sub.ptr.sub.i.i = sub i64 %sub.ptr.lhs.cast.i.i, %sub.ptr.rhs.cast.i.i
+  %cmp.i = icmp ult i64 %sub.ptr.sub.i.i, 8
   br i1 %cmp.i, label %if.then.i, label %if.else.i
 
 if.then.i:                                        ; preds = %if.end23
   %call5.i.i.i.i.i17 = tail call noalias noundef nonnull dereferenceable(8) ptr @_Znwm(i64 noundef 8) #20
   %17 = ptrtoint ptr %14 to i64
   store i64 %17, ptr %call5.i.i.i.i.i17, align 8
-  %tobool.not.i.i16 = icmp eq ptr %15, null
+  %tobool.not.i.i16 = icmp eq ptr %16, null
   br i1 %tobool.not.i.i16, label %_ZNSt12_Vector_baseIPN7rocksdb12FileMetaDataESaIS2_EE13_M_deallocateEPS2_m.exit.i, label %if.then.i13.i
 
 if.then.i13.i:                                    ; preds = %if.then.i
-  tail call void @_ZdlPv(ptr noundef nonnull %15) #17
+  tail call void @_ZdlPv(ptr noundef nonnull %16) #17
   br label %_ZNSt12_Vector_baseIPN7rocksdb12FileMetaDataESaIS2_EE13_M_deallocateEPS2_m.exit.i
 
 _ZNSt12_Vector_baseIPN7rocksdb12FileMetaDataESaIS2_EE13_M_deallocateEPS2_m.exit.i: ; preds = %if.then.i13.i, %if.then.i
@@ -3212,12 +3215,14 @@ _ZNSt12_Vector_baseIPN7rocksdb12FileMetaDataESaIS2_EE13_M_deallocateEPS2_m.exit.
 
 if.else.i:                                        ; preds = %if.end23
   %18 = load ptr, ptr %_M_finish.i.i13, align 8
-  %cmp24.not.i = icmp eq ptr %18, %16
-  %19 = ptrtoint ptr %14 to i64
-  store i64 %19, ptr %16, align 8
-  br i1 %cmp24.not.i, label %_ZSt22__uninitialized_copy_aIPKPN7rocksdb12FileMetaDataEPS2_S2_ET0_T_S7_S6_RSaIT1_E.exit.i, label %if.then25.i
+  %sub.ptr.lhs.cast.i14.i = ptrtoint ptr %18 to i64
+  %sub.ptr.sub.i16.i = sub i64 %sub.ptr.lhs.cast.i14.i, %sub.ptr.rhs.cast.i.i
+  %cmp24.not.i = icmp ult i64 %sub.ptr.sub.i16.i, 8
+  br i1 %cmp24.not.i, label %_ZSt7advanceIPKPN7rocksdb12FileMetaDataEmEvRT_T0_.exit.i, label %if.then25.i
 
 if.then25.i:                                      ; preds = %if.else.i
+  %19 = ptrtoint ptr %14 to i64
+  store i64 %19, ptr %16, align 8
   %.pre.i = load ptr, ptr %_M_finish.i.i13, align 8
   %add.ptr.i.i.i.i.i.i = getelementptr inbounds ptr, ptr %16, i64 1
   %tobool.not.i19.i = icmp eq ptr %.pre.i, %add.ptr.i.i.i.i.i.i
@@ -3227,18 +3232,30 @@ invoke.cont.i.i14:                                ; preds = %if.then25.i
   store ptr %add.ptr.i.i.i.i.i.i, ptr %_M_finish.i.i13, align 8
   br label %invoke.cont24
 
-_ZSt22__uninitialized_copy_aIPKPN7rocksdb12FileMetaDataEPS2_S2_ET0_T_S7_S6_RSaIT1_E.exit.i: ; preds = %if.else.i
-  %add.ptr.i.i.i.i.i.i.i.i.i = getelementptr inbounds ptr, ptr %16, i64 1
+_ZSt7advanceIPKPN7rocksdb12FileMetaDataEmEvRT_T0_.exit.i: ; preds = %if.else.i
+  %tobool.not.i.i.i.i.i28.i = icmp eq ptr %18, %16
+  br i1 %tobool.not.i.i.i.i.i28.i, label %if.then.i.i.i.i.i.i.i.i.i, label %if.then.i.i.i.i.i29.i
+
+if.then.i.i.i.i.i29.i:                            ; preds = %_ZSt7advanceIPKPN7rocksdb12FileMetaDataEmEvRT_T0_.exit.i
+  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %16, ptr nonnull align 8 %ref.tmp.sroa.0, i64 %sub.ptr.sub.i16.i, i1 false)
+  %.pre51.i = load ptr, ptr %_M_finish.i.i13, align 8
+  br label %if.then.i.i.i.i.i.i.i.i.i
+
+if.then.i.i.i.i.i.i.i.i.i:                        ; preds = %_ZSt7advanceIPKPN7rocksdb12FileMetaDataEmEvRT_T0_.exit.i, %if.then.i.i.i.i.i29.i
+  %20 = phi ptr [ %16, %_ZSt7advanceIPKPN7rocksdb12FileMetaDataEmEvRT_T0_.exit.i ], [ %.pre51.i, %if.then.i.i.i.i.i29.i ]
+  %21 = ptrtoint ptr %14 to i64
+  store i64 %21, ptr %20, align 8
+  %add.ptr.i.i.i.i.i.i.i.i.i = getelementptr inbounds ptr, ptr %20, i64 1
   store ptr %add.ptr.i.i.i.i.i.i.i.i.i, ptr %_M_finish.i.i13, align 8
   br label %invoke.cont24
 
-invoke.cont24:                                    ; preds = %_ZNSt12_Vector_baseIPN7rocksdb12FileMetaDataESaIS2_EE13_M_deallocateEPS2_m.exit.i, %if.then25.i, %invoke.cont.i.i14, %_ZSt22__uninitialized_copy_aIPKPN7rocksdb12FileMetaDataEPS2_S2_ET0_T_S7_S6_RSaIT1_E.exit.i
-  %20 = load i32, ptr %start_level_, align 8
-  store i32 %20, ptr %start_level_inputs_, align 8
-  %21 = load ptr, ptr %compaction_picker_24, align 8
-  %22 = load ptr, ptr %this, align 8
-  %23 = load ptr, ptr %vstorage_, align 8
-  %call32 = tail call noundef zeroext i1 @_ZN7rocksdb16CompactionPicker22ExpandInputsToCleanCutERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_18VersionStorageInfoEPNS_20CompactionInputFilesEPPNS_11InternalKeyE(ptr noundef nonnull align 8 dereferenceable(128) %21, ptr noundef nonnull align 8 dereferenceable(32) %22, ptr noundef %23, ptr noundef nonnull %start_level_inputs_, ptr noundef null)
+invoke.cont24:                                    ; preds = %_ZNSt12_Vector_baseIPN7rocksdb12FileMetaDataESaIS2_EE13_M_deallocateEPS2_m.exit.i, %if.then25.i, %invoke.cont.i.i14, %if.then.i.i.i.i.i.i.i.i.i
+  %22 = load i32, ptr %start_level_, align 8
+  store i32 %22, ptr %start_level_inputs_, align 8
+  %23 = load ptr, ptr %compaction_picker_24, align 8
+  %24 = load ptr, ptr %this, align 8
+  %25 = load ptr, ptr %vstorage_, align 8
+  %call32 = tail call noundef zeroext i1 @_ZN7rocksdb16CompactionPicker22ExpandInputsToCleanCutERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_18VersionStorageInfoEPNS_20CompactionInputFilesEPPNS_11InternalKeyE(ptr noundef nonnull align 8 dereferenceable(128) %23, ptr noundef nonnull align 8 dereferenceable(32) %24, ptr noundef %25, ptr noundef nonnull %start_level_inputs_, ptr noundef null)
   br i1 %call32, label %return, label %for.inc
 
 for.inc:                                          ; preds = %land.lhs.true11.thread, %invoke.cont24, %land.lhs.true, %land.lhs.true11
@@ -3248,14 +3265,14 @@ for.inc:                                          ; preds = %land.lhs.true11.thr
 
 for.end:                                          ; preds = %for.inc, %entry
   %files39 = getelementptr inbounds %"class.rocksdb::(anonymous namespace)::LevelCompactionBuilder", ptr %this, i64 0, i32 11, i32 1
-  %24 = load ptr, ptr %files39, align 8
+  %26 = load ptr, ptr %files39, align 8
   %_M_finish.i.i = getelementptr inbounds %"class.rocksdb::(anonymous namespace)::LevelCompactionBuilder", ptr %this, i64 0, i32 11, i32 1, i32 0, i32 0, i32 0, i32 1
-  %25 = load ptr, ptr %_M_finish.i.i, align 8
-  %tobool.not.i.i = icmp eq ptr %25, %24
+  %27 = load ptr, ptr %_M_finish.i.i, align 8
+  %tobool.not.i.i = icmp eq ptr %27, %26
   br i1 %tobool.not.i.i, label %return, label %invoke.cont.i.i
 
 invoke.cont.i.i:                                  ; preds = %for.end
-  store ptr %24, ptr %_M_finish.i.i, align 8
+  store ptr %26, ptr %_M_finish.i.i, align 8
   br label %return
 
 return:                                           ; preds = %invoke.cont24, %invoke.cont.i.i, %for.end
@@ -5086,8 +5103,7 @@ entry:
   %sub.ptr.lhs.cast.i = ptrtoint ptr %0 to i64
   %sub.ptr.rhs.cast.i = ptrtoint ptr %1 to i64
   %sub.ptr.sub.i = sub i64 %sub.ptr.lhs.cast.i, %sub.ptr.rhs.cast.i
-  %sub.ptr.div.i = ashr exact i64 %sub.ptr.sub.i, 4
-  %cmp = icmp ugt i64 %sub.ptr.div.i.i.i, %sub.ptr.div.i
+  %cmp = icmp ugt i64 %sub.ptr.sub.i.i.i, %sub.ptr.sub.i
   br i1 %cmp, label %if.then, label %if.else
 
 if.then:                                          ; preds = %entry
@@ -5129,8 +5145,7 @@ if.else:                                          ; preds = %entry
   %3 = load ptr, ptr %_M_finish.i, align 8
   %sub.ptr.lhs.cast.i7 = ptrtoint ptr %3 to i64
   %sub.ptr.sub.i9 = sub i64 %sub.ptr.lhs.cast.i7, %sub.ptr.rhs.cast.i
-  %sub.ptr.div.i10 = ashr exact i64 %sub.ptr.sub.i9, 4
-  %cmp32.not = icmp ult i64 %sub.ptr.div.i10, %sub.ptr.div.i.i.i
+  %cmp32.not = icmp ult i64 %sub.ptr.sub.i9, %sub.ptr.sub.i.i.i
   br i1 %cmp32.not, label %_ZSt7advanceIN9__gnu_cxx17__normal_iteratorIPKSt4pairIiPN7rocksdb12FileMetaDataEESt6vectorIS6_SaIS6_EEEEmEvRT_T0_.exit, label %if.then33
 
 if.then33:                                        ; preds = %if.else
@@ -5168,6 +5183,7 @@ invoke.cont.i:                                    ; preds = %_ZSt4copyIN9__gnu_c
   br label %if.end61
 
 _ZSt7advanceIN9__gnu_cxx17__normal_iteratorIPKSt4pairIiPN7rocksdb12FileMetaDataEESt6vectorIS6_SaIS6_EEEEmEvRT_T0_.exit: ; preds = %if.else
+  %sub.ptr.div.i10 = ashr exact i64 %sub.ptr.sub.i9, 4
   %incdec.ptr.i.i.i = getelementptr inbounds %"struct.std::pair", ptr %__first.coerce, i64 %sub.ptr.div.i10
   %cmp6.i.i.i.i.i22 = icmp sgt i64 %sub.ptr.div.i10, 0
   br i1 %cmp6.i.i.i.i.i22, label %for.body.i.i.i.i.i24, label %_ZSt4copyIN9__gnu_cxx17__normal_iteratorIPKSt4pairIiPN7rocksdb12FileMetaDataEESt6vectorIS6_SaIS6_EEEEPS6_ET0_T_SF_SE_.exit34
@@ -5243,8 +5259,7 @@ if.then:                                          ; preds = %entry
   %sub.ptr.lhs.cast.i14 = ptrtoint ptr %2 to i64
   %sub.ptr.rhs.cast.i15 = ptrtoint ptr %3 to i64
   %sub.ptr.sub.i16 = sub i64 %sub.ptr.lhs.cast.i14, %sub.ptr.rhs.cast.i15
-  %sub.ptr.div.i17 = ashr exact i64 %sub.ptr.sub.i16, 4
-  %cmp3 = icmp ugt i64 %sub.ptr.div.i, %sub.ptr.div.i17
+  %cmp3 = icmp ugt i64 %sub.ptr.sub.i, %sub.ptr.sub.i16
   br i1 %cmp3, label %cond.true.i.i, label %if.else
 
 cond.true.i.i:                                    ; preds = %if.then
@@ -5287,8 +5302,7 @@ if.else:                                          ; preds = %if.then
   %8 = load ptr, ptr %_M_finish.i19, align 8
   %sub.ptr.lhs.cast.i20 = ptrtoint ptr %8 to i64
   %sub.ptr.sub.i22 = sub i64 %sub.ptr.lhs.cast.i20, %sub.ptr.rhs.cast.i15
-  %sub.ptr.div.i23 = ashr exact i64 %sub.ptr.sub.i22, 4
-  %cmp26.not = icmp ult i64 %sub.ptr.div.i23, %sub.ptr.div.i
+  %cmp26.not = icmp ult i64 %sub.ptr.sub.i22, %sub.ptr.sub.i
   br i1 %cmp26.not, label %if.else49, label %if.then27
 
 if.then27:                                        ; preds = %if.else

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/velox/optimized/Filter.cpp.ll b/bench/velox/optimized/Filter.cpp.ll
index 31f08280..25a8a91d 100644
--- a/bench/velox/optimized/Filter.cpp.ll
+++ b/bench/velox/optimized/Filter.cpp.ll
@@ -8385,31 +8385,39 @@ land.rhs:                                         ; preds = %land.lhs.true5
   %sub.ptr.rhs.cast.i11 = ptrtoint ptr %18 to i64
   %sub.ptr.sub.i12 = sub i64 %sub.ptr.lhs.cast.i10, %sub.ptr.rhs.cast.i11
   %sub.ptr.div.i13 = ashr exact i64 %sub.ptr.sub.i12, 3
-  %cmp11 = icmp eq i64 %sub.ptr.div.i, %sub.ptr.div.i13
-  br i1 %cmp11, label %for.cond.preheader.split, label %return
+  %cmp11 = icmp eq i64 %sub.ptr.sub.i, %sub.ptr.sub.i12
+  br i1 %cmp11, label %for.cond.preheader, label %return
 
-for.cond.preheader.split:                         ; preds = %land.rhs
+for.cond.preheader:                               ; preds = %land.rhs
   %cmp1429.not = icmp eq ptr %15, %16
   br i1 %cmp1429.not, label %return, label %_ZNKSt6vectorIlSaIlEE2atEm.exit.preheader
 
-_ZNKSt6vectorIlSaIlEE2atEm.exit.preheader:        ; preds = %for.cond.preheader.split
+_ZNKSt6vectorIlSaIlEE2atEm.exit.preheader:        ; preds = %for.cond.preheader
   %umax = tail call i64 @llvm.umax.i64(i64 %sub.ptr.div.i, i64 1)
   br label %_ZNKSt6vectorIlSaIlEE2atEm.exit
 
-_ZNKSt6vectorIlSaIlEE2atEm.exit:                  ; preds = %_ZNKSt6vectorIlSaIlEE2atEm.exit, %_ZNKSt6vectorIlSaIlEE2atEm.exit.preheader
-  %i.030 = phi i64 [ 0, %_ZNKSt6vectorIlSaIlEE2atEm.exit.preheader ], [ %inc, %_ZNKSt6vectorIlSaIlEE2atEm.exit ]
+_ZNKSt6vectorIlSaIlEE2atEm.exit:                  ; preds = %_ZNKSt6vectorIlSaIlEE2atEm.exit27, %_ZNKSt6vectorIlSaIlEE2atEm.exit.preheader
+  %i.030 = phi i64 [ 0, %_ZNKSt6vectorIlSaIlEE2atEm.exit.preheader ], [ %inc, %_ZNKSt6vectorIlSaIlEE2atEm.exit27 ]
+  %exitcond.not = icmp eq i64 %i.030, %sub.ptr.div.i13
+  br i1 %exitcond.not, label %if.then.i.i25, label %_ZNKSt6vectorIlSaIlEE2atEm.exit27
+
+if.then.i.i25:                                    ; preds = %_ZNKSt6vectorIlSaIlEE2atEm.exit
+  tail call void (ptr, ...) @_ZSt24__throw_out_of_range_fmtPKcz(ptr noundef nonnull @.str.114, i64 noundef %sub.ptr.div.i13, i64 noundef %sub.ptr.div.i13) #37
+  unreachable
+
+_ZNKSt6vectorIlSaIlEE2atEm.exit27:                ; preds = %_ZNKSt6vectorIlSaIlEE2atEm.exit
   %add.ptr.i.i = getelementptr inbounds i64, ptr %16, i64 %i.030
   %19 = load i64, ptr %add.ptr.i.i, align 8
   %add.ptr.i.i26 = getelementptr inbounds i64, ptr %18, i64 %i.030
   %20 = load i64, ptr %add.ptr.i.i26, align 8
   %cmp19.not = icmp eq i64 %19, %20
   %inc = add nuw i64 %i.030, 1
-  %exitcond.not = icmp ne i64 %inc, %umax
-  %or.cond.not = select i1 %cmp19.not, i1 %exitcond.not, i1 false
+  %exitcond33.not = icmp ne i64 %inc, %umax
+  %or.cond.not = select i1 %cmp19.not, i1 %exitcond33.not, i1 false
   br i1 %or.cond.not, label %_ZNKSt6vectorIlSaIlEE2atEm.exit, label %return, !llvm.loop !115
 
-return:                                           ; preds = %_ZNKSt6vectorIlSaIlEE2atEm.exit, %for.cond.preheader.split, %land.lhs.true, %land.lhs.true.i, %land.lhs.true5, %land.lhs.true2, %_ZNK8facebook5velox6common6Filter17testingBaseEqualsERKS2_.exit, %entry, %land.rhs
-  %retval.0 = phi i1 [ false, %land.rhs ], [ false, %entry ], [ false, %_ZNK8facebook5velox6common6Filter17testingBaseEqualsERKS2_.exit ], [ false, %land.lhs.true2 ], [ false, %land.lhs.true5 ], [ false, %land.lhs.true.i ], [ false, %land.lhs.true ], [ true, %for.cond.preheader.split ], [ %cmp19.not, %_ZNKSt6vectorIlSaIlEE2atEm.exit ]
+return:                                           ; preds = %_ZNKSt6vectorIlSaIlEE2atEm.exit27, %for.cond.preheader, %land.lhs.true, %land.lhs.true.i, %land.lhs.true5, %land.lhs.true2, %_ZNK8facebook5velox6common6Filter17testingBaseEqualsERKS2_.exit, %entry, %land.rhs
+  %retval.0 = phi i1 [ false, %land.rhs ], [ false, %entry ], [ false, %_ZNK8facebook5velox6common6Filter17testingBaseEqualsERKS2_.exit ], [ false, %land.lhs.true2 ], [ false, %land.lhs.true5 ], [ false, %land.lhs.true.i ], [ false, %land.lhs.true ], [ true, %for.cond.preheader ], [ %cmp19.not, %_ZNKSt6vectorIlSaIlEE2atEm.exit27 ]
   ret i1 %retval.0
 }
 
@@ -48041,7 +48049,7 @@ _ZSt13move_backwardIN9__gnu_cxx17__normal_iteratorIPlSt6vectorIlSaIlEEEES6_ET0_T
   %sub.ptr.div.i.i.i.i.i.i34.i = ashr exact i64 %sub.ptr.sub.i.i.i.i.i.i33.i, 3
   %.pre.i.i.i.i.i.i35.i = sub nsw i64 0, %sub.ptr.div.i.i.i.i.i.i34.i
   %add.ptr.i.i.i.i.i.i36.i = getelementptr inbounds i64, ptr %add.ptr.i3.i31.i, i64 %.pre.i.i.i.i.i.i35.i
-  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %add.ptr.i.i.i.i.i.i36.i, ptr nonnull align 8 %__first.coerce, i64 %sub.ptr.sub.i.i.i.i.i.i33.i, i1 false)
+  tail call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1) %add.ptr.i.i.i.i.i.i36.i, ptr noundef nonnull align 8 dereferenceable(1) %__first.coerce, i64 %sub.ptr.sub.i.i.i.i.i.i33.i, i1 false)
   br label %for.inc.i21.i
 
 if.else.i19.i:                                    ; preds = %for.body.i15.i

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 26, 2023

Regression:

diff --git a/bench/arrow/optimized/tz.cpp.ll b/bench/arrow/optimized/tz.cpp.ll
index 5f76c84d..cc65491d 100644
--- a/bench/arrow/optimized/tz.cpp.ll
+++ b/bench/arrow/optimized/tz.cpp.ll
@@ -1162,8 +1162,7 @@ _ZN14arrow_vendored4dateL6parse3B5cxx11ERSi.exit.i.i.i: ; preds = %invoke.cont12
 invoke.cont.i31.i.i:                              ; preds = %_ZN14arrow_vendored4dateL6parse3B5cxx11ERSi.exit.i.i.i
   %sub.ptr.lhs.cast.i.i.i = ptrtoint ptr %call.i.i4.i.i.i to i64
   %sub.ptr.sub.i.i.i = sub i64 %sub.ptr.lhs.cast.i.i.i, %sub.ptr.rhs.cast.i.i.i
-  %sub.ptr.div.i.i.i = ashr exact i64 %sub.ptr.sub.i.i.i, 3
-  %cmp.not.i.i70.i = icmp slt i64 %sub.ptr.div.i.i.i, 12
+  %cmp.not.i.i70.i = icmp slt i64 %sub.ptr.sub.i.i.i, 96
   br i1 %cmp.not.i.i70.i, label %invoke.cont45.i.i, label %if.then.i.i71.i
 
 if.then.i.i71.i:                                  ; preds = %invoke.cont.i31.i.i
@@ -1223,24 +1222,27 @@ invoke.cont45.i.i:                                ; preds = %invoke.cont.i31.i.i
           to label %invoke.cont67.i.i unwind label %lpad37.loopexit.i.i, !noalias !17
 
 invoke.cont67.i.i:                                ; preds = %invoke.cont45.i.i
-  %55 = trunc i64 %sub.ptr.div.i.i.i to i8
+  %55 = trunc i64 %sub.ptr.sub.i.i.i to i32
   %56 = load i32, ptr %y.i.i, align 4, !noalias !17
-  %57 = load i32, ptr %d.i.i, align 4, !noalias !17
-  %58 = add i8 %55, 1
+  %57 = shl i32 %55, 13
+  %retval.sroa.2.0.insert.shift.i.i.i.i = add i32 %57, 65536
+  %58 = load i32, ptr %d.i.i, align 4, !noalias !17
+  %ref.tmp53.sroa.2.0.extract.shift.i.i = lshr i32 %retval.sroa.2.0.insert.shift.i.i.i.i, 16
+  %ref.tmp53.sroa.2.0.extract.trunc.i.i = trunc i32 %ref.tmp53.sroa.2.0.extract.shift.i.i to i8
   %sext.i.i = shl i32 %56, 16
   %conv.i.i.i.i.i = ashr exact i32 %sext.i.i, 16
-  %cmp.i.i.i.i.i.i = icmp ult i8 %58, 3
+  %cmp.i.i.i.i.i.i = icmp ult i8 %ref.tmp53.sroa.2.0.extract.trunc.i.i, 3
   %conv.neg.i.i.i.i = sext i1 %cmp.i.i.i.i.i.i to i32
   %sub.i.i.i72.i = add nsw i32 %conv.i.i.i.i.i, %conv.neg.i.i.i.i
-  %conv.i11.i.i.i.i = zext i8 %58 to i32
-  %conv.i12.i.i.i.i = and i32 %57, 255
+  %conv.i11.i.i.i.i = and i32 %ref.tmp53.sroa.2.0.extract.shift.i.i, 255
+  %conv.i12.i.i.i.i = and i32 %58, 255
   %sub6.i.i.i.i = add nsw i32 %sub.i.i.i72.i, -399
   %cmp9.i.i.i.i = icmp slt i32 %sub.i.i.i72.i, 0
   %cond.i.i.i.i = select i1 %cmp9.i.i.i.i, i32 %sub6.i.i.i.i, i32 %sub.i.i.i72.i
   %div.i.i.i.i = sdiv i32 %cond.i.i.i.i, 400
   %mul.neg.i.i.i.i = mul nsw i32 %div.i.i.i.i, -400
   %sub7.i.i.i.i = add nsw i32 %mul.neg.i.i.i.i, %sub.i.i.i72.i
-  %cmp8.i.i.i.i = icmp ugt i8 %58, 2
+  %cmp8.i.i.i.i = icmp ugt i8 %ref.tmp53.sroa.2.0.extract.trunc.i.i, 2
   %cond13.v.i.i.i.i = select i1 %cmp8.i.i.i.i, i32 -3, i32 9
   %cond13.i.i.i.i = add nsw i32 %cond13.v.i.i.i.i, %conv.i11.i.i.i.i
   %mul14.i.i.i.i = mul nsw i32 %cond13.i.i.i.i, 153

We lose the information that both of the loaded pointers are aligned to 8 bytes.
Clang is responsible for adding the !align metadata for a load of pointer.

llvm/llvm-project@cb366f3

@nikic
Copy link

nikic commented Dec 27, 2023

@dtcxzyw You can't emit !align on raw pointers, only on references.

@dtcxzyw
Copy link
Owner Author

dtcxzyw commented Dec 27, 2023

@dtcxzyw You can't emit !align on raw pointers, only on references.

You are right. Another way to handle this is to preserve alignment information of ashr exact i64 %sub.ptr.sub.i.i.i, 3 in DCE. Then we can compute KnownBits from @llvm.assume.

@nikic
Copy link

nikic commented Dec 27, 2023

@dtcxzyw Adding random assumes from transforms is almost certainly a pessimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants