[llvm] r315056 - Re-land "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion."

Clement Courbet via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 6 05:12:35 PDT 2017


Author: courbet
Date: Fri Oct  6 05:12:35 2017
New Revision: 315056

URL: http://llvm.org/viewvc/llvm-project?rev=315056&view=rev
Log:
Re-land "[MergeICmps] Disable mergeicmps if the target does not want to handle memcmp expansion."

(fixed unit tests by making comparisons stable)

This reverts commit 1b2d359ce256fd6737da4e93833346a0bd6d7583.

Added:
    llvm/trunk/test/Transforms/MergeICmps/X86/lit.local.cfg
    llvm/trunk/test/Transforms/MergeICmps/X86/pair-int32-int32.ll
      - copied, changed from r314985, llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll
    llvm/trunk/test/Transforms/MergeICmps/X86/tuple-four-int8.ll
      - copied, changed from r314985, llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll
    llvm/trunk/test/Transforms/MergeICmps/X86/volatile.ll
Removed:
    llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll
    llvm/trunk/test/Transforms/MergeICmps/volatile.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp
    llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll

Modified: llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp?rev=315056&r1=315055&r2=315056&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/MergeICmps.cpp Fri Oct  6 05:12:35 2017
@@ -28,6 +28,8 @@
 #include <vector>
 #include "llvm/ADT/APSInt.h"
 #include "llvm/Analysis/Loads.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/IntrinsicInst.h"
@@ -41,8 +43,6 @@ namespace {
 
 #define DEBUG_TYPE "mergeicmps"
 
-#define MERGEICMPS_DOT_ON
-
 // A BCE atom.
 struct BCEAtom {
   BCEAtom() : GEP(nullptr), LoadI(nullptr), Offset() {}
@@ -50,7 +50,21 @@ struct BCEAtom {
   const Value *Base() const { return GEP ? GEP->getPointerOperand() : nullptr; }
 
   bool operator<(const BCEAtom &O) const {
-    return Base() == O.Base() ? Offset.slt(O.Offset) : Base() < O.Base();
+    assert(Base() && "invalid atom");
+    assert(O.Base() && "invalid atom");
+    // Just ordering by (Base(), Offset) is sufficient. However because this
+    // means that the ordering will depend on the addresses of the base
+    // values, which are not reproducible from run to run. To guarantee
+    // stability, we use the names of the values if they exist; we sort by:
+    // (Base.getName(), Base(), Offset).
+    const int NameCmp = Base()->getName().compare(O.Base()->getName());
+    if (NameCmp == 0) {
+      if (Base() == O.Base()) {
+        return Offset.slt(O.Offset);
+      }
+      return Base() < O.Base();
+    }
+    return NameCmp < 0;
   }
 
   GetElementPtrInst *GEP;
@@ -99,7 +113,9 @@ BCEAtom visitICmpLoadOperand(Value *cons
 
 // A basic block with a comparison between two BCE atoms.
 // Note: the terminology is misleading: the comparison is symmetric, so there
-// is no real {l/r}hs. To break the symmetry, we use the smallest atom as Lhs.
+// is no real {l/r}hs. What we want though is to have the same base on the
+// left (resp. right), so that we can detect consecutive loads. To ensure this
+// we put the smallest atom on the left.
 class BCECmpBlock {
  public:
   BCECmpBlock() {}
@@ -430,10 +446,9 @@ void BCECmpChain::mergeComparisons(Array
 
     IRBuilder<> Builder(BB);
     const auto &DL = Phi.getModule()->getDataLayout();
-    Value *const MemCmpCall =
-        emitMemCmp(FirstComparison.Lhs().GEP, FirstComparison.Rhs().GEP,
-                   ConstantInt::get(DL.getIntPtrType(Context), TotalSize),
-                   Builder, DL, TLI);
+    Value *const MemCmpCall = emitMemCmp(
+        FirstComparison.Lhs().GEP, FirstComparison.Rhs().GEP, ConstantInt::get(DL.getIntPtrType(Context), TotalSize),
+        Builder, DL, TLI);
     Value *const MemCmpIsZero = Builder.CreateICmpEQ(
         MemCmpCall, ConstantInt::get(Type::getInt32Ty(Context), 0));
 
@@ -589,22 +604,30 @@ class MergeICmps : public FunctionPass {
   bool runOnFunction(Function &F) override {
     if (skipFunction(F)) return false;
     const auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
-    auto PA = runImpl(F, &TLI);
+    const auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
+    auto PA = runImpl(F, &TLI, &TTI);
     return !PA.areAllPreserved();
   }
 
  private:
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<TargetLibraryInfoWrapperPass>();
+    AU.addRequired<TargetTransformInfoWrapperPass>();
   }
 
-  PreservedAnalyses runImpl(Function &F, const TargetLibraryInfo *TLI);
+  PreservedAnalyses runImpl(Function &F, const TargetLibraryInfo *TLI,
+                            const TargetTransformInfo *TTI);
 };
 
-PreservedAnalyses MergeICmps::runImpl(Function &F,
-                                      const TargetLibraryInfo *TLI) {
+PreservedAnalyses MergeICmps::runImpl(Function &F, const TargetLibraryInfo *TLI,
+                                      const TargetTransformInfo *TTI) {
   DEBUG(dbgs() << "MergeICmpsPass: " << F.getName() << "\n");
 
+  // We only try merging comparisons if the target wants to expand memcmp later.
+  // The rationale is to avoid turning small chains into memcmp calls.
+  unsigned MaxLoadSize;
+  if (!TTI->enableMemCmpExpansion(MaxLoadSize)) return PreservedAnalyses::all();
+
   bool MadeChange = false;
 
   for (auto BBIt = ++F.begin(); BBIt != F.end(); ++BBIt) {
@@ -623,6 +646,7 @@ char MergeICmps::ID = 0;
 INITIALIZE_PASS_BEGIN(MergeICmps, "mergeicmps",
                       "Merge contiguous icmps into a memcmp", false, false)
 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
 INITIALIZE_PASS_END(MergeICmps, "mergeicmps",
                     "Merge contiguous icmps into a memcmp", false, false)
 

Added: llvm/trunk/test/Transforms/MergeICmps/X86/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeICmps/X86/lit.local.cfg?rev=315056&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/MergeICmps/X86/lit.local.cfg (added)
+++ llvm/trunk/test/Transforms/MergeICmps/X86/lit.local.cfg Fri Oct  6 05:12:35 2017
@@ -0,0 +1,3 @@
+if not 'X86' in config.root.targets:
+    config.unsupported = True
+

Copied: llvm/trunk/test/Transforms/MergeICmps/X86/pair-int32-int32.ll (from r314985, llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeICmps/X86/pair-int32-int32.ll?p2=llvm/trunk/test/Transforms/MergeICmps/X86/pair-int32-int32.ll&p1=llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll&r1=314985&r2=315056&rev=315056&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll (original)
+++ llvm/trunk/test/Transforms/MergeICmps/X86/pair-int32-int32.ll Fri Oct  6 05:12:35 2017
@@ -1,10 +1,24 @@
-; RUN: opt -mergeicmps -S -o - %s | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -mergeicmps -mtriple=x86_64-unknown-unknown -S | FileCheck %s --check-prefix=X86
 
 %"struct.std::pair" = type { i32, i32 }
 
 define zeroext i1 @opeq1(
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
+; X86-LABEL: @opeq1(
+; X86-NEXT:  entry:
+; X86-NEXT:    [[FIRST_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A:%.*]], i64 0, i32 0
+; X86-NEXT:    [[FIRST1_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B:%.*]], i64 0, i32 0
+; X86-NEXT:    [[CSTR:%.*]] = bitcast i32* [[FIRST_I]] to i8*
+; X86-NEXT:    [[CSTR1:%.*]] = bitcast i32* [[FIRST1_I]] to i8*
+; X86-NEXT:    [[MEMCMP:%.*]] = call i32 @memcmp(i8* [[CSTR]], i8* [[CSTR1]], i64 8)
+; X86-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[MEMCMP]], 0
+; X86-NEXT:    br label [[OPEQ1_EXIT:%.*]]
+; X86:       opeq1.exit:
+; X86-NEXT:    [[TMP1:%.*]] = phi i1 [ [[TMP0]], [[ENTRY:%.*]] ]
+; X86-NEXT:    ret i1 [[TMP1]]
+;
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
 entry:
   %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 0
   %0 = load i32, i32* %first.i, align 4
@@ -24,28 +38,29 @@ land.rhs.i:
 opeq1.exit:
   %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ]
   ret i1 %4
-; CHECK-LABEL: @opeq1(
 ; The entry block with zero-offset GEPs is kept, loads are removed.
-; CHECK: entry
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
 ; The two 4 byte loads and compares are replaced with a single 8-byte memcmp.
-; CHECK:     @memcmp({{.*}}8)
-; CHECK:     icmp eq {{.*}} 0
 ; The branch is now a direct branch; the other block has been removed.
-; CHECK:     br label %opeq1.exit
-; CHECK-NOT: br
 ; The phi is updated.
-; CHECK:      phi i1 [ %{{[^,]*}}, %entry ]
-; CHECK-NEXT: ret
 }
 
 ; Same as above, but the two blocks are in inverse order.
 define zeroext i1 @opeq1_inverse(
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
+; X86-LABEL: @opeq1_inverse(
+; X86-NEXT:  land.rhs.i:
+; X86-NEXT:    [[SECOND_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A:%.*]], i64 0, i32 0
+; X86-NEXT:    [[SECOND2_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B:%.*]], i64 0, i32 0
+; X86-NEXT:    [[CSTR:%.*]] = bitcast i32* [[SECOND_I]] to i8*
+; X86-NEXT:    [[CSTR1:%.*]] = bitcast i32* [[SECOND2_I]] to i8*
+; X86-NEXT:    [[MEMCMP:%.*]] = call i32 @memcmp(i8* [[CSTR]], i8* [[CSTR1]], i64 8)
+; X86-NEXT:    [[TMP0:%.*]] = icmp eq i32 [[MEMCMP]], 0
+; X86-NEXT:    br label [[OPEQ1_EXIT:%.*]]
+; X86:       opeq1.exit:
+; X86-NEXT:    [[TMP1:%.*]] = phi i1 [ [[TMP0]], [[LAND_RHS_I:%.*]] ]
+; X86-NEXT:    ret i1 [[TMP1]]
+;
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
 entry:
   %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 1
   %0 = load i32, i32* %first.i, align 4
@@ -65,22 +80,11 @@ land.rhs.i:
 opeq1.exit:
   %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ]
   ret i1 %4
-; CHECK-LABEL: @opeq1_inverse(
 ; The second block with zero-offset GEPs is kept, loads are removed.
 ; CHECK: land.rhs.i
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
 ; The two 4 byte loads and compares are replaced with a single 8-byte memcmp.
-; CHECK:     @memcmp({{.*}}8)
-; CHECK:     icmp eq {{.*}} 0
 ; The branch is now a direct branch; the other block has been removed.
-; CHECK:     br label %opeq1.exit
-; CHECK-NOT: br
 ; The phi is updated.
-; CHECK:      phi i1 [ %{{[^,]*}}, %land.rhs.i ]
-; CHECK-NEXT: ret
 }
 
 

Copied: llvm/trunk/test/Transforms/MergeICmps/X86/tuple-four-int8.ll (from r314985, llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeICmps/X86/tuple-four-int8.ll?p2=llvm/trunk/test/Transforms/MergeICmps/X86/tuple-four-int8.ll&p1=llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll&r1=314985&r2=315056&rev=315056&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll (original)
+++ llvm/trunk/test/Transforms/MergeICmps/X86/tuple-four-int8.ll Fri Oct  6 05:12:35 2017
@@ -1,4 +1,5 @@
-; RUN: opt -mergeicmps -S -o - %s | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -mergeicmps -mtriple=x86_64-unknown-unknown -S | FileCheck %s
 
 ; This is a more involved test: clang generates this weird pattern for
 ; tuple<uint8_t, uint8_t, uint8_t, uint8_t>. Right now we skip the entry block
@@ -17,8 +18,33 @@
 %"struct.std::_Head_base.6" = type { i8 }
 
 define zeroext i1 @opeq(
-    %"class.std::tuple"* nocapture readonly dereferenceable(4) %a,
-    %"class.std::tuple"* nocapture readonly dereferenceable(4) %b) local_unnamed_addr #1 {
+; CHECK-LABEL: @opeq(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* [[A:%.*]], i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
+; CHECK-NEXT:    [[ADD_PTR_I_I_I_I_I:%.*]] = getelementptr inbounds i8, i8* [[TMP0]], i64 3
+; CHECK-NEXT:    [[TMP1:%.*]] = load i8, i8* [[ADD_PTR_I_I_I_I_I]], align 1
+; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* [[B:%.*]], i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
+; CHECK-NEXT:    [[ADD_PTR_I_I_I6_I_I:%.*]] = getelementptr inbounds i8, i8* [[TMP2]], i64 3
+; CHECK-NEXT:    [[TMP3:%.*]] = load i8, i8* [[ADD_PTR_I_I_I6_I_I]], align 1
+; CHECK-NEXT:    [[CMP_I_I:%.*]] = icmp eq i8 [[TMP1]], [[TMP3]]
+; CHECK-NEXT:    br i1 [[CMP_I_I]], label [[LAND_RHS_I_I_I:%.*]], label [[OPEQ_EXIT:%.*]]
+; CHECK:       land.rhs.i.i.i:
+; CHECK-NEXT:    [[ADD_PTR_I_I_I_I_I_I_I:%.*]] = getelementptr inbounds i8, i8* [[TMP0]], i64 1
+; CHECK-NEXT:    [[ADD_PTR_I_I_I6_I_I_I_I:%.*]] = getelementptr inbounds i8, i8* [[TMP2]], i64 1
+; CHECK-NEXT:    [[MEMCMP:%.*]] = call i32 @memcmp(i8* [[ADD_PTR_I_I_I6_I_I_I_I]], i8* [[ADD_PTR_I_I_I_I_I_I_I]], i64 2)
+; CHECK-NEXT:    [[TMP4:%.*]] = icmp eq i32 [[MEMCMP]], 0
+; CHECK-NEXT:    br i1 [[TMP4]], label [[LAND_RHS_I_I_I_I:%.*]], label [[OPEQ_EXIT]]
+; CHECK:       land.rhs.i.i.i.i:
+; CHECK-NEXT:    [[TMP5:%.*]] = load i8, i8* [[TMP0]], align 1
+; CHECK-NEXT:    [[TMP6:%.*]] = load i8, i8* [[TMP2]], align 1
+; CHECK-NEXT:    [[CMP_I_I_I_I_I:%.*]] = icmp eq i8 [[TMP5]], [[TMP6]]
+; CHECK-NEXT:    br label [[OPEQ_EXIT]]
+; CHECK:       opeq.exit:
+; CHECK-NEXT:    [[TMP7:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ false, [[LAND_RHS_I_I_I]] ], [ [[CMP_I_I_I_I_I]], [[LAND_RHS_I_I_I_I]] ]
+; CHECK-NEXT:    ret i1 [[TMP7]]
+;
+  %"class.std::tuple"* nocapture readonly dereferenceable(4) %a,
+  %"class.std::tuple"* nocapture readonly dereferenceable(4) %b) local_unnamed_addr #1 {
 entry:
   %0 = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* %a, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
   %add.ptr.i.i.i.i.i = getelementptr inbounds i8, i8* %0, i64 3
@@ -54,18 +80,11 @@ land.rhs.i.i.i.i:
 opeq.exit:
   %10 = phi i1 [ false, %entry ], [ false, %land.rhs.i.i ], [ false, %land.rhs.i.i.i ], [ %cmp.i.i.i.i.i, %land.rhs.i.i.i.i ]
   ret i1 %10
-; CHECK-LABEL: @opeq(
 ; The entry block is kept as is, but the next block is now the merged comparison
 ; block for bytes [1,2] or the block for the head.
-; CHECK:     entry
-; CHECK:     br i1 %cmp.i.i, label %land.rhs.i.i.i{{(.i)?}}, label %opeq.exit
 ; The two 1 byte loads and compares at offset 1 are replaced with a single
 ; 2-byte memcmp.
-; CHECK:     land.rhs.i.i.i
-; CHECK:     @memcmp({{.*}}2)
-; CHECK:     icmp eq {{.*}} 0
 ; In the end we have three blocks.
-; CHECK: phi i1
 ; CHECK-SAME %entry
 ; CHECK-SAME %land.rhs.i.i.i.i
 ; CHECK-SAME %land.rhs.i.i.i

Added: llvm/trunk/test/Transforms/MergeICmps/X86/volatile.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeICmps/X86/volatile.ll?rev=315056&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/MergeICmps/X86/volatile.ll (added)
+++ llvm/trunk/test/Transforms/MergeICmps/X86/volatile.ll Fri Oct  6 05:12:35 2017
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -mergeicmps -mtriple=x86_64-unknown-unknown -S | FileCheck %s
+
+%"struct.std::pair" = type { i32, i32 }
+
+define zeroext i1 @opeq(
+; CHECK-LABEL: @opeq(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[FIRST_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A:%.*]], i64 0, i32 0
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, i32* [[FIRST_I]], align 4
+; CHECK-NEXT:    [[FIRST1_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B:%.*]], i64 0, i32 0
+; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[FIRST1_I]], align 4
+; CHECK-NEXT:    [[CMP_I:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
+; CHECK-NEXT:    br i1 [[CMP_I]], label [[LAND_RHS_I:%.*]], label [[OPEQ1_EXIT:%.*]]
+; CHECK:       land.rhs.i:
+; CHECK-NEXT:    [[SECOND_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A]], i64 0, i32 1
+; CHECK-NEXT:    [[TMP2:%.*]] = load volatile i32, i32* [[SECOND_I]], align 4
+; CHECK-NEXT:    [[SECOND2_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B]], i64 0, i32 1
+; CHECK-NEXT:    [[TMP3:%.*]] = load i32, i32* [[SECOND2_I]], align 4
+; CHECK-NEXT:    [[CMP3_I:%.*]] = icmp eq i32 [[TMP2]], [[TMP3]]
+; CHECK-NEXT:    br label [[OPEQ1_EXIT]]
+; CHECK:       opeq1.exit:
+; CHECK-NEXT:    [[TMP4:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[CMP3_I]], [[LAND_RHS_I]] ]
+; CHECK-NEXT:    ret i1 [[TMP4]]
+;
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
+entry:
+  %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 0
+  %0 = load i32, i32* %first.i, align 4
+  %first1.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 0
+  %1 = load i32, i32* %first1.i, align 4
+  %cmp.i = icmp eq i32 %0, %1
+  br i1 %cmp.i, label %land.rhs.i, label %opeq1.exit
+
+land.rhs.i:
+  %second.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 1
+  %2 = load volatile i32, i32* %second.i, align 4
+  %second2.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 1
+  %3 = load i32, i32* %second2.i, align 4
+  %cmp3.i = icmp eq i32 %2, %3
+  br label %opeq1.exit
+
+opeq1.exit:
+  %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ]
+  ret i1 %4
+}
+

Modified: llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll?rev=315056&r1=315055&r2=315056&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll (original)
+++ llvm/trunk/test/Transforms/MergeICmps/pair-int32-int32.ll Fri Oct  6 05:12:35 2017
@@ -1,10 +1,30 @@
-; RUN: opt -mergeicmps -S -o - %s | FileCheck %s
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -mergeicmps -S | FileCheck %s --check-prefix=NOEXPANSION
 
 %"struct.std::pair" = type { i32, i32 }
 
 define zeroext i1 @opeq1(
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
+; NOEXPANSION-LABEL: @opeq1(
+; NOEXPANSION-NEXT:  entry:
+; NOEXPANSION-NEXT:    [[FIRST_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A:%.*]], i64 0, i32 0
+; NOEXPANSION-NEXT:    [[TMP0:%.*]] = load i32, i32* [[FIRST_I]], align 4
+; NOEXPANSION-NEXT:    [[FIRST1_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B:%.*]], i64 0, i32 0
+; NOEXPANSION-NEXT:    [[TMP1:%.*]] = load i32, i32* [[FIRST1_I]], align 4
+; NOEXPANSION-NEXT:    [[CMP_I:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
+; NOEXPANSION-NEXT:    br i1 [[CMP_I]], label [[LAND_RHS_I:%.*]], label [[OPEQ1_EXIT:%.*]]
+; NOEXPANSION:       land.rhs.i:
+; NOEXPANSION-NEXT:    [[SECOND_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A]], i64 0, i32 1
+; NOEXPANSION-NEXT:    [[TMP2:%.*]] = load i32, i32* [[SECOND_I]], align 4
+; NOEXPANSION-NEXT:    [[SECOND2_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B]], i64 0, i32 1
+; NOEXPANSION-NEXT:    [[TMP3:%.*]] = load i32, i32* [[SECOND2_I]], align 4
+; NOEXPANSION-NEXT:    [[CMP3_I:%.*]] = icmp eq i32 [[TMP2]], [[TMP3]]
+; NOEXPANSION-NEXT:    br label [[OPEQ1_EXIT]]
+; NOEXPANSION:       opeq1.exit:
+; NOEXPANSION-NEXT:    [[TMP4:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[CMP3_I]], [[LAND_RHS_I]] ]
+; NOEXPANSION-NEXT:    ret i1 [[TMP4]]
+;
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
 entry:
   %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 0
   %0 = load i32, i32* %first.i, align 4
@@ -24,28 +44,31 @@ land.rhs.i:
 opeq1.exit:
   %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ]
   ret i1 %4
-; CHECK-LABEL: @opeq1(
-; The entry block with zero-offset GEPs is kept, loads are removed.
-; CHECK: entry
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
-; The two 4 byte loads and compares are replaced with a single 8-byte memcmp.
-; CHECK:     @memcmp({{.*}}8)
-; CHECK:     icmp eq {{.*}} 0
-; The branch is now a direct branch; the other block has been removed.
-; CHECK:     br label %opeq1.exit
-; CHECK-NOT: br
-; The phi is updated.
-; CHECK:      phi i1 [ %{{[^,]*}}, %entry ]
-; CHECK-NEXT: ret
 }
 
 ; Same as above, but the two blocks are in inverse order.
 define zeroext i1 @opeq1_inverse(
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
+; NOEXPANSION-LABEL: @opeq1_inverse(
+; NOEXPANSION-NEXT:  entry:
+; NOEXPANSION-NEXT:    [[FIRST_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A:%.*]], i64 0, i32 1
+; NOEXPANSION-NEXT:    [[TMP0:%.*]] = load i32, i32* [[FIRST_I]], align 4
+; NOEXPANSION-NEXT:    [[FIRST1_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B:%.*]], i64 0, i32 1
+; NOEXPANSION-NEXT:    [[TMP1:%.*]] = load i32, i32* [[FIRST1_I]], align 4
+; NOEXPANSION-NEXT:    [[CMP_I:%.*]] = icmp eq i32 [[TMP0]], [[TMP1]]
+; NOEXPANSION-NEXT:    br i1 [[CMP_I]], label [[LAND_RHS_I:%.*]], label [[OPEQ1_EXIT:%.*]]
+; NOEXPANSION:       land.rhs.i:
+; NOEXPANSION-NEXT:    [[SECOND_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[A]], i64 0, i32 0
+; NOEXPANSION-NEXT:    [[TMP2:%.*]] = load i32, i32* [[SECOND_I]], align 4
+; NOEXPANSION-NEXT:    [[SECOND2_I:%.*]] = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* [[B]], i64 0, i32 0
+; NOEXPANSION-NEXT:    [[TMP3:%.*]] = load i32, i32* [[SECOND2_I]], align 4
+; NOEXPANSION-NEXT:    [[CMP3_I:%.*]] = icmp eq i32 [[TMP2]], [[TMP3]]
+; NOEXPANSION-NEXT:    br label [[OPEQ1_EXIT]]
+; NOEXPANSION:       opeq1.exit:
+; NOEXPANSION-NEXT:    [[TMP4:%.*]] = phi i1 [ false, [[ENTRY:%.*]] ], [ [[CMP3_I]], [[LAND_RHS_I]] ]
+; NOEXPANSION-NEXT:    ret i1 [[TMP4]]
+;
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
+  %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
 entry:
   %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 1
   %0 = load i32, i32* %first.i, align 4
@@ -65,22 +88,6 @@ land.rhs.i:
 opeq1.exit:
   %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ]
   ret i1 %4
-; CHECK-LABEL: @opeq1_inverse(
-; The second block with zero-offset GEPs is kept, loads are removed.
-; CHECK: land.rhs.i
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
-; CHECK:     getelementptr {{.*}} i32 0
-; CHECK-NOT: load
-; The two 4 byte loads and compares are replaced with a single 8-byte memcmp.
-; CHECK:     @memcmp({{.*}}8)
-; CHECK:     icmp eq {{.*}} 0
-; The branch is now a direct branch; the other block has been removed.
-; CHECK:     br label %opeq1.exit
-; CHECK-NOT: br
-; The phi is updated.
-; CHECK:      phi i1 [ %{{[^,]*}}, %land.rhs.i ]
-; CHECK-NEXT: ret
 }
 
 

Removed: llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll?rev=315055&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll (original)
+++ llvm/trunk/test/Transforms/MergeICmps/tuple-four-int8.ll (removed)
@@ -1,73 +0,0 @@
-; RUN: opt -mergeicmps -S -o - %s | FileCheck %s
-
-; This is a more involved test: clang generates this weird pattern for
-; tuple<uint8_t, uint8_t, uint8_t, uint8_t>. Right now we skip the entry block
-; (which defines the base pointer for other blocks) and the last one (which
-; does not have the expected structure). Only middle blocks (bytes [1,2]) are
-; merged.
-
-%"class.std::tuple" = type { %"struct.std::_Tuple_impl" }
-%"struct.std::_Tuple_impl" = type { %"struct.std::_Tuple_impl.0", %"struct.std::_Head_base.6" }
-%"struct.std::_Tuple_impl.0" = type { %"struct.std::_Tuple_impl.1", %"struct.std::_Head_base.5" }
-%"struct.std::_Tuple_impl.1" = type { %"struct.std::_Tuple_impl.2", %"struct.std::_Head_base.4" }
-%"struct.std::_Tuple_impl.2" = type { %"struct.std::_Head_base" }
-%"struct.std::_Head_base" = type { i8 }
-%"struct.std::_Head_base.4" = type { i8 }
-%"struct.std::_Head_base.5" = type { i8 }
-%"struct.std::_Head_base.6" = type { i8 }
-
-define zeroext i1 @opeq(
-    %"class.std::tuple"* nocapture readonly dereferenceable(4) %a,
-    %"class.std::tuple"* nocapture readonly dereferenceable(4) %b) local_unnamed_addr #1 {
-entry:
-  %0 = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* %a, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
-  %add.ptr.i.i.i.i.i = getelementptr inbounds i8, i8* %0, i64 3
-  %1 = load i8, i8* %add.ptr.i.i.i.i.i, align 1
-  %2 = getelementptr inbounds %"class.std::tuple", %"class.std::tuple"* %b, i64 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0
-  %add.ptr.i.i.i6.i.i = getelementptr inbounds i8, i8* %2, i64 3
-  %3 = load i8, i8* %add.ptr.i.i.i6.i.i, align 1
-  %cmp.i.i = icmp eq i8 %1, %3
-  br i1 %cmp.i.i, label %land.rhs.i.i, label %opeq.exit
-
-land.rhs.i.i:
-  %add.ptr.i.i.i.i.i.i = getelementptr inbounds i8, i8* %0, i64 2
-  %4 = load i8, i8* %add.ptr.i.i.i.i.i.i, align 1
-  %add.ptr.i.i.i6.i.i.i = getelementptr inbounds i8, i8* %2, i64 2
-  %5 = load i8, i8* %add.ptr.i.i.i6.i.i.i, align 1
-  %cmp.i.i.i = icmp eq i8 %4, %5
-  br i1 %cmp.i.i.i, label %land.rhs.i.i.i, label %opeq.exit
-
-land.rhs.i.i.i:
-  %add.ptr.i.i.i.i.i.i.i = getelementptr inbounds i8, i8* %0, i64 1
-  %6 = load i8, i8* %add.ptr.i.i.i.i.i.i.i, align 1
-  %add.ptr.i.i.i6.i.i.i.i = getelementptr inbounds i8, i8* %2, i64 1
-  %7 = load i8, i8* %add.ptr.i.i.i6.i.i.i.i, align 1
-  %cmp.i.i.i.i = icmp eq i8 %6, %7
-  br i1 %cmp.i.i.i.i, label %land.rhs.i.i.i.i, label %opeq.exit
-
-land.rhs.i.i.i.i:
-  %8 = load i8, i8* %0, align 1
-  %9 = load i8, i8* %2, align 1
-  %cmp.i.i.i.i.i = icmp eq i8 %8, %9
-  br label %opeq.exit
-
-opeq.exit:
-  %10 = phi i1 [ false, %entry ], [ false, %land.rhs.i.i ], [ false, %land.rhs.i.i.i ], [ %cmp.i.i.i.i.i, %land.rhs.i.i.i.i ]
-  ret i1 %10
-; CHECK-LABEL: @opeq(
-; The entry block is kept as is, but the next block is now the merged comparison
-; block for bytes [1,2] or the block for the head.
-; CHECK:     entry
-; CHECK:     br i1 %cmp.i.i, label %land.rhs.i.i.i{{(.i)?}}, label %opeq.exit
-; The two 1 byte loads and compares at offset 1 are replaced with a single
-; 2-byte memcmp.
-; CHECK:     land.rhs.i.i.i
-; CHECK:     @memcmp({{.*}}2)
-; CHECK:     icmp eq {{.*}} 0
-; In the end we have three blocks.
-; CHECK: phi i1
-; CHECK-SAME %entry
-; CHECK-SAME %land.rhs.i.i.i.i
-; CHECK-SAME %land.rhs.i.i.i
-}
-

Removed: llvm/trunk/test/Transforms/MergeICmps/volatile.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MergeICmps/volatile.ll?rev=315055&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/MergeICmps/volatile.ll (original)
+++ llvm/trunk/test/Transforms/MergeICmps/volatile.ll (removed)
@@ -1,30 +0,0 @@
-; RUN: opt -mergeicmps -S -o - %s | FileCheck %s
-
-%"struct.std::pair" = type { i32, i32 }
-
-define zeroext i1 @opeq(
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %a,
-    %"struct.std::pair"* nocapture readonly dereferenceable(8) %b) local_unnamed_addr #0 {
-entry:
-  %first.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 0
-  %0 = load i32, i32* %first.i, align 4
-  %first1.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 0
-  %1 = load i32, i32* %first1.i, align 4
-  %cmp.i = icmp eq i32 %0, %1
-  br i1 %cmp.i, label %land.rhs.i, label %opeq1.exit
-
-land.rhs.i:
-  %second.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %a, i64 0, i32 1
-  %2 = load volatile i32, i32* %second.i, align 4
-  %second2.i = getelementptr inbounds %"struct.std::pair", %"struct.std::pair"* %b, i64 0, i32 1
-  %3 = load i32, i32* %second2.i, align 4
-  %cmp3.i = icmp eq i32 %2, %3
-  br label %opeq1.exit
-
-opeq1.exit:
-  %4 = phi i1 [ false, %entry ], [ %cmp3.i, %land.rhs.i ]
-  ret i1 %4
-; CHECK-LABEL: @opeq(
-; CHECK-NOT: memcmp
-}
-




More information about the llvm-commits mailing list