[llvm] [GISel] Teach computeKnownBitsImpl to handle COPY instructions that change bit width. (PR #118924)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 21:20:26 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
The selectShiftMask ComplexRenderFn on RISCV calls computeKnownBits.
I encountered a case where we looked through a G_PHI and found a COPY that was created from an already selected G_ANYEXT from s32 to s64. s32 and s64 integers on RISC-V end up in the same register class. The input to the COPY was an already selected s32 SELECT instruction. We need an s32 SELECT to be legal to support f32 selects. If it isn't used by FP operations, regbank select will assign to GPR.
This patch uses KnownBits::anyextOrTrunc to adjust the width when they mismatch.
I haven't reduced a test case yet, but wanted to make sure this is the right fix.
---
Full diff: https://github.com/llvm/llvm-project/pull/118924.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp (+1)
``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
index 30cd3ce3baa502..6c15ed3423d3bd 100644
--- a/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -253,6 +253,7 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
// For COPYs we don't do anything, don't increase the depth.
computeKnownBitsImpl(SrcReg, Known2, DemandedElts,
Depth + (Opcode != TargetOpcode::COPY));
+ Known2 = Known2.anyextOrTrunc(BitWidth);
Known = Known.intersectWith(Known2);
// If we reach a point where we don't know anything
// just stop looking through the operands.
``````````
</details>
https://github.com/llvm/llvm-project/pull/118924
More information about the llvm-commits
mailing list