[llvm] 3c0096a - [MergeICmps] Don't call comesBefore() if in different blocks (PR53959)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 22 03:27:28 PST 2022
Author: Nikita Popov
Date: 2022-02-22T12:27:20+01:00
New Revision: 3c0096a1d45689389e11c385fd4ab98fdec80323
URL: https://github.com/llvm/llvm-project/commit/3c0096a1d45689389e11c385fd4ab98fdec80323
DIFF: https://github.com/llvm/llvm-project/commit/3c0096a1d45689389e11c385fd4ab98fdec80323.diff
LOG: [MergeICmps] Don't call comesBefore() if in different blocks (PR53959)
Only call comesBefore() if the instructions are in the same block.
Otherwise make a conservative assumption.
Fixes https://github.com/llvm/llvm-project/issues/53959.
Added:
llvm/test/Transforms/MergeICmps/X86/pr53959.ll
Modified:
llvm/lib/Transforms/Scalar/MergeICmps.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
index aac0deea5be3d..d38e362015ed7 100644
--- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -244,7 +244,7 @@ bool BCECmpBlock::canSinkBCECmpInst(const Instruction *Inst,
auto MayClobber = [&](LoadInst *LI) {
// If a potentially clobbering instruction comes before the load,
// we can still safely sink the load.
- return !Inst->comesBefore(LI) &&
+ return (Inst->getParent() != LI->getParent() || !Inst->comesBefore(LI)) &&
isModSet(AA.getModRefInfo(Inst, MemoryLocation::get(LI)));
};
if (MayClobber(Cmp.Lhs.LoadI) || MayClobber(Cmp.Rhs.LoadI))
diff --git a/llvm/test/Transforms/MergeICmps/X86/pr53959.ll b/llvm/test/Transforms/MergeICmps/X86/pr53959.ll
new file mode 100644
index 0000000000000..b7ba8bd39ba53
--- /dev/null
+++ b/llvm/test/Transforms/MergeICmps/X86/pr53959.ll
@@ -0,0 +1,48 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -mergeicmps < %s | FileCheck %s
+
+target triple = "x86_64-unknown-linux-gnu"
+
+ at c = external global i32, align 4
+
+define i1 @d() {
+; CHECK-LABEL: @d(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[G:%.*]] = alloca [8 x i64], align 16
+; CHECK-NEXT: [[IDX1:%.*]] = getelementptr inbounds [8 x i64], [8 x i64]* [[G]], i64 0, i64 0
+; CHECK-NEXT: [[V1:%.*]] = load i64, i64* [[IDX1]], align 8
+; CHECK-NEXT: [[IDX2:%.*]] = getelementptr inbounds [8 x i64], [8 x i64]* [[G]], i64 0, i64 0
+; CHECK-NEXT: [[V2:%.*]] = load i64, i64* [[IDX2]], align 8
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[V1]], [[V2]]
+; CHECK-NEXT: br label [[SPLIT:%.*]]
+; CHECK: split:
+; CHECK-NEXT: [[X:%.*]] = load volatile i32, i32* @c, align 4
+; CHECK-NEXT: br i1 [[CMP]], label [[IF:%.*]], label [[EXIT:%.*]]
+; CHECK: if:
+; CHECK-NEXT: [[TOBOOL:%.*]] = icmp ne i32 [[X]], 0
+; CHECK-NEXT: br label [[EXIT]]
+; CHECK: exit:
+; CHECK-NEXT: [[P:%.*]] = phi i1 [ false, [[SPLIT]] ], [ [[TOBOOL]], [[IF]] ]
+; CHECK-NEXT: ret i1 [[P]]
+;
+entry:
+ %g = alloca [8 x i64], align 16
+ %idx1 = getelementptr inbounds [8 x i64], [8 x i64]* %g, i64 0, i64 0
+ %v1 = load i64, i64* %idx1, align 8
+ %idx2 = getelementptr inbounds [8 x i64], [8 x i64]* %g, i64 0, i64 0
+ %v2 = load i64, i64* %idx2, align 8
+ %cmp = icmp eq i64 %v1, %v2
+ br label %split
+
+split:
+ %x = load volatile i32, i32* @c, align 4
+ br i1 %cmp, label %if, label %exit
+
+if:
+ %tobool = icmp ne i32 %x, 0
+ br label %exit
+
+exit:
+ %p = phi i1 [ false, %split ], [ %tobool, %if ]
+ ret i1 %p
+}
More information about the llvm-commits
mailing list