File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -120,8 +120,10 @@ bool InstPromoter::visitICmpInst(ICmpInst &I) {
120
120
unsigned finalWidth = LHS->getType ()->getIntegerBitWidth ();
121
121
122
122
if (!isSigned) {
123
- LHS = IRB->CreateAnd (LHS, (1 << initialWidth) - 1 );
124
- RHS = IRB->CreateAnd (RHS, (1 << initialWidth) - 1 );
123
+ APInt M = APInt::getLowBitsSet (finalWidth, initialWidth);
124
+ auto *MaskC = ConstantInt::get (LHS->getType (), M);
125
+ LHS = IRB->CreateAnd (LHS, MaskC);
126
+ RHS = IRB->CreateAnd (RHS, MaskC);
125
127
} else {
126
128
IGC_ASSERT (finalWidth >= initialWidth);
127
129
Original file line number Diff line number Diff line change
1
+ ;=========================== begin_copyright_notice ============================
2
+ ;
3
+ ; Copyright (C) 2025 Intel Corporation
4
+ ;
5
+ ; SPDX-License-Identifier: MIT
6
+ ;
7
+ ;============================ end_copyright_notice =============================
8
+ ;
9
+ ; RUN: igc_opt -igc-type-legalizer -S < %s | FileCheck %s
10
+ ; ------------------------------------------------
11
+ ; Legalization: icmp (i40 -> i64 promotion mask correctness)
12
+ ; ------------------------------------------------
13
+ ;
14
+ ; Ensure that unsigned icmp on an illegal integer width (i40) is promoted
15
+ ; with a correct low-40-bit mask (0xFFFFFFFFFF = 1099511627775).
16
+ ;
17
+ ; CHECK-LABEL: define i1 @test_icmp_i40
18
+ ; CHECK: %[[TRUNC:.*]] = and i64 %[[X:.*]], 1099511627775
19
+ ; CHECK: %[[MASKED:.*]] = and i64 %[[TRUNC]], 1099511627775
20
+ ; CHECK: icmp ult i64 %[[MASKED]], 4294967296
21
+ ; CHECK: ret i1
22
+
23
+ define i1 @test_icmp_i40 (i64 %x ) {
24
+ ; Truncate to illegal width i40, then compare with 1<<32
25
+ %t = trunc i64 %x to i40
26
+ %cmp = icmp ult i40 %t , 4294967296
27
+ ret i1 %cmp
28
+ }
You can’t perform that action at this time.
0 commit comments