Skip to content

Commit

Permalink
[DAG] SimplifyShift - shift i1/vXi1 X, Y --> X (any non-zero shift am…
Browse files Browse the repository at this point in the history
…ount is undefined).

Alive2: https://alive2.llvm.org/ce/z/SdESbg

Fixes #85681
  • Loading branch information
RKSimon committed Mar 19, 2024
1 parent 12a6546 commit 2377b97
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9595,6 +9595,10 @@ SDValue SelectionDAG::simplifyShift(SDValue X, SDValue Y) {
if (ISD::matchUnaryPredicate(Y, isShiftTooBig, true))
return getUNDEF(X.getValueType());

// shift i1/vXi1 X, Y --> X (any non-zero shift amount is undefined).
if (X.getValueType().getScalarType() == MVT::i1)
return X;

return SDValue();
}

Expand Down
41 changes: 41 additions & 0 deletions llvm/test/CodeGen/X86/pr85681.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
; RUN: llc < %s -mtriple=x86_64-- -mcpu=emeraldrapids | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v2 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v3 | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-- -mcpu=x86-64-v4 | FileCheck %s

; PR85681 - shift i1/vXi1 X, Y -> X as only Y==0 is defined

define i32 @shl(i32 %a0) {
; CHECK-LABEL: shl:
; CHECK: # %bb.0:
; CHECK-NEXT: movl $-1, %eax
; CHECK-NEXT: retq
%v0 = bitcast i32 %a0 to <32 x i1>
%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
%r = bitcast <32 x i1> %s to i32
ret i32 %r
}

define i32 @lshr(i32 %a0) {
; CHECK-LABEL: lshr:
; CHECK: # %bb.0:
; CHECK-NEXT: movl $-1, %eax
; CHECK-NEXT: retq
%v0 = bitcast i32 %a0 to <32 x i1>
%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
%r = bitcast <32 x i1> %s to i32
ret i32 %r
}

define i32 @ashr(i32 %a0) {
; CHECK-LABEL: ashr:
; CHECK: # %bb.0:
; CHECK-NEXT: movl $-1, %eax
; CHECK-NEXT: retq
%v0 = bitcast i32 %a0 to <32 x i1>
%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
%r = bitcast <32 x i1> %s to i32
ret i32 %r
}

0 comments on commit 2377b97

Please sign in to comment.