aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorValentin Churavy <v.churavy@gmail.com>2021-08-27 17:20:14 +0200
committerTom Stellard <tstellar@redhat.com>2021-11-09 20:58:52 -0800
commit8be24d19fefadb6c1c4d5b9c31a1ab4b51ce1435 (patch)
treed56becbaeb371b332fcf20581db50b0d02556a30 /llvm
parent9e084f4194e6a06c3b94be4358975da333d05146 (diff)
downloadllvm-8be24d19fefadb6c1c4d5b9c31a1ab4b51ce1435.zip
llvm-8be24d19fefadb6c1c4d5b9c31a1ab4b51ce1435.tar.gz
llvm-8be24d19fefadb6c1c4d5b9c31a1ab4b51ce1435.tar.bz2
[MergeICmps] Don't merge icmps derived from pointers with addressspaces
IIUC we can't emit `memcmp` between pointers in addressspaces, doing so will trigger an assertion since the signature of the memcmp will not match it's arguments (https://bugs.llvm.org/show_bug.cgi?id=48661). This PR disables the attempt to merge icmps, when the pointer is in an addressspace. Reviewed By: #julialang, vtjnash Differential Revision: https://reviews.llvm.org/D94813 (cherry picked from commit 4cacb5cad052b14d37703157f3b7ffc6a6610acc)
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Scalar/MergeICmps.cpp4
-rw-r--r--llvm/test/Transforms/MergeICmps/X86/addressspaces.ll94
2 files changed, 98 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
index f13f24a..a04d4ef 100644
--- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -154,6 +154,10 @@ BCEAtom visitICmpLoadOperand(Value *const Val, BaseIdentifier &BaseId) {
return {};
}
Value *const Addr = LoadI->getOperand(0);
+ if (Addr->getType()->getPointerAddressSpace() != 0) {
+ LLVM_DEBUG(dbgs() << "from non-zero AddressSpace\n");
+ return {};
+ }
auto *const GEP = dyn_cast<GetElementPtrInst>(Addr);
if (!GEP)
return {};
diff --git a/llvm/test/Transforms/MergeICmps/X86/addressspaces.ll b/llvm/test/Transforms/MergeICmps/X86/addressspaces.ll
new file mode 100644
index 0000000..a1db03c
--- /dev/null
+++ b/llvm/test/Transforms/MergeICmps/X86/addressspaces.ll
@@ -0,0 +1,94 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -S -mergeicmps -verify-dom-info | FileCheck %s
+target triple = "x86_64"
+
+; First check that we try to from a memcmp.
+define void @form_memcmp([2 x i64]* dereferenceable(16) %a, [2 x i64]* dereferenceable(16) %b) {
+; CHECK-LABEL: @form_memcmp(
+; CHECK-NEXT: bb0:
+; CHECK-NEXT: [[PTR_A0:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A:%.*]], i64 0, i64 0
+; CHECK-NEXT: [[PTR_A1:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A]], i64 0, i64 1
+; CHECK-NEXT: [[PTR_B0:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[B:%.*]], i64 0, i64 0
+; CHECK-NEXT: [[PTR_B1:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[B]], i64 0, i64 1
+; CHECK-NEXT: br label %"bb1+bb2"
+; CHECK: "bb1+bb2":
+; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[A]], i64 0, i64 0
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [2 x i64], [2 x i64]* [[B]], i64 0, i64 0
+; CHECK-NEXT: [[CSTR:%.*]] = bitcast i64* [[TMP0]] to i8*
+; CHECK-NEXT: [[CSTR1:%.*]] = bitcast i64* [[TMP1]] to i8*
+; CHECK-NEXT: [[MEMCMP:%.*]] = call i32 @memcmp(i8* [[CSTR]], i8* [[CSTR1]], i64 16)
+; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[MEMCMP]], 0
+; CHECK-NEXT: br label [[BB3:%.*]]
+; CHECK: bb3:
+; CHECK-NEXT: ret void
+;
+bb0:
+ %ptr_a0 = getelementptr inbounds [2 x i64], [2 x i64]* %a, i64 0, i64 0
+ %ptr_a1 = getelementptr inbounds [2 x i64], [2 x i64]* %a, i64 0, i64 1
+ %ptr_b0 = getelementptr inbounds [2 x i64], [2 x i64]* %b, i64 0, i64 0
+ %ptr_b1 = getelementptr inbounds [2 x i64], [2 x i64]* %b, i64 0, i64 1
+ br label %bb1
+
+bb1: ; preds = %bb0
+ %a0 = load i64, i64* %ptr_a0
+ %b0 = load i64, i64* %ptr_b0
+ %cond0 = icmp eq i64 %a0, %b0
+ br i1 %cond0, label %bb2, label %bb3
+
+bb2: ; preds = %bb1
+ %a1 = load i64, i64* %ptr_a1
+ %b1 = load i64, i64* %ptr_b1
+ %cond1 = icmp eq i64 %a1, %b1
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ %necessary = phi i1 [ %cond1, %bb2 ], [ false, %bb1 ]
+ ret void
+}
+
+; We can't use memcmp between arbitrary addressesspaces
+define void @no_memcmp([2 x i64] addrspace(11)* dereferenceable(16) %a, [2 x i64] addrspace(11)* dereferenceable(16) %b) {
+; CHECK-LABEL: @no_memcmp(
+; CHECK-NEXT: bb0:
+; CHECK-NEXT: [[PTR_A0:%.*]] = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* [[A:%.*]], i64 0, i64 0
+; CHECK-NEXT: [[PTR_A1:%.*]] = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* [[A]], i64 0, i64 1
+; CHECK-NEXT: [[PTR_B0:%.*]] = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* [[B:%.*]], i64 0, i64 0
+; CHECK-NEXT: [[PTR_B1:%.*]] = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* [[B]], i64 0, i64 1
+; CHECK-NEXT: br label [[BB1:%.*]]
+; CHECK: bb1:
+; CHECK-NEXT: [[A0:%.*]] = load i64, i64 addrspace(11)* [[PTR_A0]], align 4
+; CHECK-NEXT: [[B0:%.*]] = load i64, i64 addrspace(11)* [[PTR_B0]], align 4
+; CHECK-NEXT: [[COND0:%.*]] = icmp eq i64 [[A0]], [[B0]]
+; CHECK-NEXT: br i1 [[COND0]], label [[BB2:%.*]], label [[BB3:%.*]]
+; CHECK: bb2:
+; CHECK-NEXT: [[A1:%.*]] = load i64, i64 addrspace(11)* [[PTR_A1]], align 4
+; CHECK-NEXT: [[B1:%.*]] = load i64, i64 addrspace(11)* [[PTR_B1]], align 4
+; CHECK-NEXT: [[COND1:%.*]] = icmp eq i64 [[A1]], [[B1]]
+; CHECK-NEXT: br label [[BB3]]
+; CHECK: bb3:
+; CHECK-NEXT: [[NECESSARY:%.*]] = phi i1 [ [[COND1]], [[BB2]] ], [ false, [[BB1]] ]
+; CHECK-NEXT: ret void
+;
+bb0:
+ %ptr_a0 = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* %a, i64 0, i64 0
+ %ptr_a1 = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* %a, i64 0, i64 1
+ %ptr_b0 = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* %b, i64 0, i64 0
+ %ptr_b1 = getelementptr inbounds [2 x i64], [2 x i64] addrspace(11)* %b, i64 0, i64 1
+ br label %bb1
+
+bb1: ; preds = %bb0
+ %a0 = load i64, i64 addrspace(11)* %ptr_a0
+ %b0 = load i64, i64 addrspace(11)* %ptr_b0
+ %cond0 = icmp eq i64 %a0, %b0
+ br i1 %cond0, label %bb2, label %bb3
+
+bb2: ; preds = %bb1
+ %a1 = load i64, i64 addrspace(11)* %ptr_a1
+ %b1 = load i64, i64 addrspace(11)* %ptr_b1
+ %cond1 = icmp eq i64 %a1, %b1
+ br label %bb3
+
+bb3: ; preds = %bb2, %bb1
+ %necessary = phi i1 [ %cond1, %bb2 ], [ false, %bb1 ]
+ ret void
+}