Skip to content

Commit 6c7957c

Browse files
committed
[SVE] Fix bug in SVEIntrinsicOpts::optimizePTest
The code wasn't taking into account that the two operands passed to ptest could be identical and was trying to erase them twice. Differential Revision: https://reviews.llvm.org/D85892
1 parent 725400f commit 6c7957c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

llvm/lib/Target/AArch64/SVEIntrinsicOpts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ bool SVEIntrinsicOpts::optimizePTest(IntrinsicInst *I) {
160160
I->eraseFromParent();
161161
if (Op1->use_empty())
162162
Op1->eraseFromParent();
163-
if (Op2->use_empty())
163+
if (Op1 != Op2 && Op2->use_empty())
164164
Op2->eraseFromParent();
165165

166166
return true;

llvm/test/CodeGen/AArch64/sve-intrinsic-opts-ptest.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ define i1 @ptest_first(<vscale x 4 x i1> %a) {
4444
ret i1 %out
4545
}
4646

47+
define i1 @ptest_first_same_ops(<vscale x 2 x i1> %a) {
48+
; OPT-LABEL: ptest_first_same_ops
49+
; OPT: %[[OUT:.*]] = call i1 @llvm.aarch64.sve.ptest.first.nxv2i1(<vscale x 2 x i1> %a, <vscale x 2 x i1> %a)
50+
; OPT-NOT: convert
51+
; OPT-NEXT: ret i1 %[[OUT]]
52+
%1 = tail call <vscale x 16 x i1> @llvm.aarch64.sve.convert.to.svbool.nxv2i1(<vscale x 2 x i1> %a)
53+
%2 = tail call i1 @llvm.aarch64.sve.ptest.first.nxv16i1(<vscale x 16 x i1> %1, <vscale x 16 x i1> %1)
54+
ret i1 %2
55+
}
56+
4757
define i1 @ptest_last(<vscale x 8 x i1> %a) {
4858
; OPT-LABEL: ptest_last
4959
; OPT: %mask = tail call <vscale x 8 x i1> @llvm.aarch64.sve.ptrue.nxv8i1(i32 0)

0 commit comments

Comments
 (0)