[llvm] 61621f8 - [TargetLowering] SimplifyDemandedBits - add basic KnownBits ZEXTLoad handling
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 3 08:51:11 PST 2020
Author: Simon Pilgrim
Date: 2020-02-03T16:50:04Z
New Revision: 61621f826a5bd100c20ca4d740b52f9c09673e96
URL: https://github.com/llvm/llvm-project/commit/61621f826a5bd100c20ca4d740b52f9c09673e96
DIFF: https://github.com/llvm/llvm-project/commit/61621f826a5bd100c20ca4d740b52f9c09673e96.diff
LOG: [TargetLowering] SimplifyDemandedBits - add basic KnownBits ZEXTLoad handling
We have to be careful in SimplifyDemandedBits with loads in case we attempt to combine back to a constant (which then gets turned into a constant pool load again), but we can at least set the upper KnownBits for a ZEXTLoad to zero.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/X86/combine-bextr.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 78fbfc552b55..49c780faf856 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -881,6 +881,12 @@ bool TargetLowering::SimplifyDemandedBits(
if (getTargetConstantFromLoad(LD)) {
Known = TLO.DAG.computeKnownBits(Op, DemandedElts, Depth);
return false; // Don't fall through, will infinitely loop.
+ } else if (ISD::isZEXTLoad(Op.getNode()) && Op.getResNo() == 0) {
+ // If this is a ZEXTLoad and we are looking at the loaded value.
+ EVT VT = LD->getMemoryVT();
+ unsigned MemBits = VT.getScalarSizeInBits();
+ Known.Zero.setBitsFrom(MemBits);
+ return false; // Don't fall through, will infinitely loop.
}
break;
}
diff --git a/llvm/test/CodeGen/X86/combine-bextr.ll b/llvm/test/CodeGen/X86/combine-bextr.ll
index 852e96ebebdd..2ec55109c337 100644
--- a/llvm/test/CodeGen/X86/combine-bextr.ll
+++ b/llvm/test/CodeGen/X86/combine-bextr.ll
@@ -1,20 +1,14 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse2,+bmi | FileCheck %s --check-prefixes=X32
-; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2,+bmi | FileCheck %s --check-prefixes=X64
+; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+sse2,+bmi | FileCheck %s --check-prefixes=CHECK,X32
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2,+bmi | FileCheck %s --check-prefixes=CHECK,X64
declare i32 @llvm.x86.bmi.bextr.32(i32, i32)
define i32 @bextr_zero_length(i32 %x, i32 %y) {
-; X32-LABEL: bextr_zero_length:
-; X32: # %bb.0:
-; X32-NEXT: movzbl {{[0-9]+}}(%esp), %eax
-; X32-NEXT: bextrl %eax, {{[0-9]+}}(%esp), %eax
-; X32-NEXT: retl
-;
-; X64-LABEL: bextr_zero_length:
-; X64: # %bb.0:
-; X64-NEXT: xorl %eax, %eax
-; X64-NEXT: retq
+; CHECK-LABEL: bextr_zero_length:
+; CHECK: # %bb.0:
+; CHECK-NEXT: xorl %eax, %eax
+; CHECK-NEXT: ret{{[l|q]}}
%1 = and i32 %y, 255
%2 = tail call i32 @llvm.x86.bmi.bextr.32(i32 %x, i32 %1)
ret i32 %2
More information about the llvm-commits
mailing list