[llvm] 56ad791 - [X86] LowerAndToBT - fold BT(NOT(X),Y) -> BT(X,Y) and flip the CondCode
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 19 07:03:17 PDT 2022
Author: Simon Pilgrim
Date: 2022-03-19T14:03:03Z
New Revision: 56ad791f462fc4fc37213696f29b8c0a5e9404f8
URL: https://github.com/llvm/llvm-project/commit/56ad791f462fc4fc37213696f29b8c0a5e9404f8
DIFF: https://github.com/llvm/llvm-project/commit/56ad791f462fc4fc37213696f29b8c0a5e9404f8.diff
LOG: [X86] LowerAndToBT - fold BT(NOT(X),Y) -> BT(X,Y) and flip the CondCode
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/avx512-insert-extract.ll
llvm/test/CodeGen/X86/bt.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 0ba6fa26c7437..20e9a21c28ad2 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -23565,6 +23565,12 @@ static SDValue LowerAndToBT(SDValue And, ISD::CondCode CC,
if (!Src.getNode())
return SDValue();
+ // Remove any bit flip.
+ if (isBitwiseNot(Src)) {
+ Src = Src.getOperand(0);
+ CC = CC == ISD::SETEQ ? ISD::SETNE : ISD::SETEQ;
+ }
+
// If Src is i8, promote it to i32 with any_extend. There is no i8 BT
// instruction. Since the shift amount is in-range-or-undefined, we know
// that doing a bittest on the i32 value is ok. We extend to i32 because
diff --git a/llvm/test/CodeGen/X86/avx512-insert-extract.ll b/llvm/test/CodeGen/X86/avx512-insert-extract.ll
index 5e0318b1984e4..d131118f63f9b 100644
--- a/llvm/test/CodeGen/X86/avx512-insert-extract.ll
+++ b/llvm/test/CodeGen/X86/avx512-insert-extract.ll
@@ -1636,10 +1636,9 @@ define zeroext i8 @test_extractelement_varible_v32i1(<32 x i8> %a, <32 x i8> %b,
; KNL-NEXT: vpminub %ymm1, %ymm0, %ymm1
; KNL-NEXT: vpcmpeqb %ymm1, %ymm0, %ymm0
; KNL-NEXT: vpmovmskb %ymm0, %ecx
-; KNL-NEXT: notl %ecx
; KNL-NEXT: xorl %eax, %eax
; KNL-NEXT: btl %edi, %ecx
-; KNL-NEXT: setb %al
+; KNL-NEXT: setae %al
; KNL-NEXT: vzeroupper
; KNL-NEXT: retq
;
diff --git a/llvm/test/CodeGen/X86/bt.ll b/llvm/test/CodeGen/X86/bt.ll
index b3c7db976b6b3..436dd4be1bb08 100644
--- a/llvm/test/CodeGen/X86/bt.ll
+++ b/llvm/test/CodeGen/X86/bt.ll
@@ -1043,17 +1043,15 @@ define zeroext i1 @invert(i32 %flags, i32 %flag) nounwind {
; X86-LABEL: invert:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
-; X86-NEXT: notl %eax
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: btl %ecx, %eax
-; X86-NEXT: setb %al
+; X86-NEXT: setae %al
; X86-NEXT: retl
;
; X64-LABEL: invert:
; X64: # %bb.0:
-; X64-NEXT: notl %edi
; X64-NEXT: btl %esi, %edi
-; X64-NEXT: setb %al
+; X64-NEXT: setae %al
; X64-NEXT: retq
%neg = xor i32 %flags, -1
%shl = shl i32 1, %flag
More information about the llvm-commits
mailing list