[llvm] [InstCombine] Fix missing argument typo in `InstCombinerImpl::foldICmpShlConstant` (PR #94899)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 10:12:58 PDT 2024
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/94899
>From b111dd909add1b9f853b92804090a433b2bbe73a Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sun, 9 Jun 2024 19:53:20 +0800
Subject: [PATCH 1/3] [InstCombine] Add pre-commit tests from PR94897. NFC.
---
llvm/test/Transforms/InstCombine/icmp.ll | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 4dbe2fc88ff71..a01c0cded2e84 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -5295,3 +5295,12 @@ define i1 @test_icmp_shl_sgt(i64 %x) {
%cmp = icmp sgt i64 %shl, 8589934591
ret i1 %cmp
}
+
+define i1 @pr94897(i32 range(i32 -2147483648, 0) %x) {
+; CHECK-LABEL: @pr94897(
+; CHECK-NEXT: ret i1 true
+;
+ %shl = shl nsw i32 %x, 24
+ %cmp = icmp ugt i32 %shl, -50331648
+ ret i1 %cmp
+}
>From ad74363176e3784bcbfe3db2dc3a76c6c47f6c08 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sun, 9 Jun 2024 20:00:42 +0800
Subject: [PATCH 2/3] [InstCombine] Fix missing argument typo in
`InstCombinerImpl::foldICmpShlConstant`
---
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 7 ++++---
llvm/test/Transforms/InstCombine/icmp.ll | 3 ++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 89193f8ff94b6..9965825e582be 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2441,9 +2441,10 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
Type *TruncTy = ShType->getWithNewBitWidth(TypeBits - Amt);
Constant *NewC =
ConstantInt::get(TruncTy, RHSC.ashr(*ShiftAmt).trunc(TypeBits - Amt));
- return new ICmpInst(
- CmpPred, Builder.CreateTrunc(X, TruncTy, "", Shl->hasNoSignedWrap()),
- NewC);
+ return new ICmpInst(CmpPred,
+ Builder.CreateTrunc(X, TruncTy, "", /*IsNUW=*/false,
+ Shl->hasNoSignedWrap()),
+ NewC);
}
}
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index a01c0cded2e84..723dbbc7101dc 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -5298,7 +5298,8 @@ define i1 @test_icmp_shl_sgt(i64 %x) {
define i1 @pr94897(i32 range(i32 -2147483648, 0) %x) {
; CHECK-LABEL: @pr94897(
-; CHECK-NEXT: ret i1 true
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], -3
+; CHECK-NEXT: ret i1 [[CMP]]
;
%shl = shl nsw i32 %x, 24
%cmp = icmp ugt i32 %shl, -50331648
>From 13faa5e454b4079fb0fe5f0a2809939706edb222 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Mon, 10 Jun 2024 01:12:31 +0800
Subject: [PATCH 3/3] [InstCombine] Add more tests. NFC.
---
llvm/test/Transforms/InstCombine/icmp.ll | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index 723dbbc7101dc..8fc4a40141931 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -5255,6 +5255,16 @@ define i1 @test_icmp_shl_nuw(i64 %x) {
ret i1 %cmp
}
+define i1 @test_icmp_shl_nuw_i31(i31 %x) {
+; CHECK-LABEL: @test_icmp_shl_nuw_i31(
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i31 [[X:%.*]], 250
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %shl = shl nuw i31 %x, 23
+ %cmp = icmp ugt i31 %shl, -50331648
+ ret i1 %cmp
+}
+
define i1 @test_icmp_shl_nsw(i64 %x) {
; CHECK-LABEL: @test_icmp_shl_nsw(
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[X:%.*]], 3
@@ -5265,6 +5275,17 @@ define i1 @test_icmp_shl_nsw(i64 %x) {
ret i1 %cmp
}
+define i1 @test_icmp_shl_nsw_i31(i31 %x) {
+; CHECK-LABEL: @test_icmp_shl_nsw_i31(
+; CHECK-NEXT: [[TMP1:%.*]] = trunc nsw i31 [[X:%.*]] to i8
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[TMP1]], -6
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %shl = shl nsw i31 %x, 23
+ %cmp = icmp ugt i31 %shl, -50331648
+ ret i1 %cmp
+}
+
define <2 x i1> @test_icmp_shl_vec(<2 x i64> %x) {
; CHECK-LABEL: @test_icmp_shl_vec(
; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i64> [[X:%.*]] to <2 x i32>
More information about the llvm-commits
mailing list