Skip to content

Commit 9fc6857

Browse files
RKSimonchencha3
authored andcommitted
[DAG] SimplifyShift - shift i1/vXi1 X, Y --> X (any non-zero shift amount is undefined).
Alive2: https://alive2.llvm.org/ce/z/SdESbg Fixes llvm#85681
1 parent 2d425d2 commit 9fc6857

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9595,6 +9595,10 @@ SDValue SelectionDAG::simplifyShift(SDValue X, SDValue Y) {
95959595
if (ISD::matchUnaryPredicate(Y, isShiftTooBig, true))
95969596
return getUNDEF(X.getValueType());
95979597

9598+
// shift i1/vXi1 X, Y --> X (any non-zero shift amount is undefined).
9599+
if (X.getValueType().getScalarType() == MVT::i1)
9600+
return X;
9601+
95989602
return SDValue();
95999603
}
96009604

llvm/test/CodeGen/X86/pr85681.ll

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2+
; RUN: llc < %s -mtriple=x86_64-- -mcpu=emeraldrapids | FileCheck %s
3+
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64 | FileCheck %s
4+
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v2 | FileCheck %s
5+
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v3 | FileCheck %s
6+
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v4 | FileCheck %s
7+
8+
; PR85681 - shift i1/vXi1 X, Y -> X as only Y==0 is defined
9+
10+
define i32 @shl(i32 %a0) {
11+
; CHECK-LABEL: shl:
12+
; CHECK: # %bb.0:
13+
; CHECK-NEXT: movl $-1, %eax
14+
; CHECK-NEXT: retq
15+
%v0 = bitcast i32 %a0 to <32 x i1>
16+
%s = shl <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, %v0
17+
%r = bitcast <32 x i1> %s to i32
18+
ret i32 %r
19+
}
20+
21+
define i32 @lshr(i32 %a0) {
22+
; CHECK-LABEL: lshr:
23+
; CHECK: # %bb.0:
24+
; CHECK-NEXT: movl $-1, %eax
25+
; CHECK-NEXT: retq
26+
%v0 = bitcast i32 %a0 to <32 x i1>
27+
%s = lshr <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, %v0
28+
%r = bitcast <32 x i1> %s to i32
29+
ret i32 %r
30+
}
31+
32+
define i32 @ashr(i32 %a0) {
33+
; CHECK-LABEL: ashr:
34+
; CHECK: # %bb.0:
35+
; CHECK-NEXT: movl $-1, %eax
36+
; CHECK-NEXT: retq
37+
%v0 = bitcast i32 %a0 to <32 x i1>
38+
%s = ashr <32 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, %v0
39+
%r = bitcast <32 x i1> %s to i32
40+
ret i32 %r
41+
}

0 commit comments

Comments
 (0)