[llvm] [X86] Added ComputeKnownBits support for BEXTR (PR #199558)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 6 13:47:23 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Analysis/ValueTracking.cpp llvm/unittests/Analysis/ValueTrackingTest.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 8ae128844..667eca12c 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2285,7 +2285,8 @@ static void computeKnownBitsFromOperator(const Operator *I,
             break;
           }
           if ((Shift + Length) <= BitWidth) {
-            computeKnownBits(I->getOperand(0), DemandedElts, Known, Q, Depth + 1);
+            computeKnownBits(I->getOperand(0), DemandedElts, Known, Q,
+                             Depth + 1);
             Known = Known.extractBits(Length, Shift);
             Known = Known.zextOrTrunc(BitWidth);
           }
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 0c751ebe0..3eb0fbbf3 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -2782,51 +2782,47 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownUSubSatZerosPreserved) {
 TEST_F(ComputeKnownBitsTest, ComputeKnownBitsX86BmiBextr32) {
   // bextr(11111111....., shift=4, length=8)
   // extracts bits [4, 12) which are all known one.
-  parseAssembly(
-      "define i32 @test(i32 %a) {\n"
-      "  %aa = or i32 %a, 4080\n"
-      "  %A = call i32 @llvm.x86.bmi.bextr.32(i32 %aa, i32 2052)\n"
-      "  ret i32 %A\n"
-      "}\n"
-      "declare i32 @llvm.x86.bmi.bextr.32(i32, i32)\n");
+  parseAssembly("define i32 @test(i32 %a) {\n"
+                "  %aa = or i32 %a, 4080\n"
+                "  %A = call i32 @llvm.x86.bmi.bextr.32(i32 %aa, i32 2052)\n"
+                "  ret i32 %A\n"
+                "}\n"
+                "declare i32 @llvm.x86.bmi.bextr.32(i32, i32)\n");
   expectKnownBits(/*zero*/ 4294967040u, /*one*/ 255u);
 }
 
 TEST_F(ComputeKnownBitsTest, ComputeKnownBitsX86TbmBextriU32Mixed) {
   // bextr(....1111....0000, shift=0, length=12)
   // extracts bits [0, 12), a mix of known and unknown bits, zero-extended.
-  parseAssembly(
-      "define i32 @test(i32 %a) {\n"
-      "  %aa = shl i32 %a, 4\n"
-      "  %aaa = or i32 %aa, 3840\n"
-      "  %A = call i32 @llvm.x86.tbm.bextri.u32(i32 %aaa, i32 3072)\n"
-      "  ret i32 %A\n"
-      "}\n"
-      "declare i32 @llvm.x86.tbm.bextri.u32(i32, i32)\n");
+  parseAssembly("define i32 @test(i32 %a) {\n"
+                "  %aa = shl i32 %a, 4\n"
+                "  %aaa = or i32 %aa, 3840\n"
+                "  %A = call i32 @llvm.x86.tbm.bextri.u32(i32 %aaa, i32 3072)\n"
+                "  ret i32 %A\n"
+                "}\n"
+                "declare i32 @llvm.x86.tbm.bextri.u32(i32, i32)\n");
   expectKnownBits(/*zero*/ 4294963215u, /*one*/ 3840u);
 }
 
 TEST_F(ComputeKnownBitsTest, ComputeKnownBitsX86BmiBextr64ZeroLength) {
   // bextr(x, shift=0, length=0) is always zero, regardless of the operand.
-  parseAssembly(
-      "define i64 @test(i64 %a) {\n"
-      "  %A = call i64 @llvm.x86.bmi.bextr.64(i64 %a, i64 0)\n"
-      "  ret i64 %A\n"
-      "}\n"
-      "declare i64 @llvm.x86.bmi.bextr.64(i64, i64)\n");
+  parseAssembly("define i64 @test(i64 %a) {\n"
+                "  %A = call i64 @llvm.x86.bmi.bextr.64(i64 %a, i64 0)\n"
+                "  ret i64 %A\n"
+                "}\n"
+                "declare i64 @llvm.x86.bmi.bextr.64(i64, i64)\n");
   expectKnownBits(/*zero*/ 18446744073709551615u, /*one*/ 0u);
 }
 
 TEST_F(ComputeKnownBitsTest, ComputeKnownBitsX86TbmBextriU32OutOfRange) {
   // shift + length (30 + 10 = 40) exceeds the bit width (32), so nothing is
   // known about the result even though the operand has known bits.
-  parseAssembly(
-      "define i32 @test(i32 %a) {\n"
-      "  %aa = or i32 %a, 4080\n"
-      "  %A = call i32 @llvm.x86.tbm.bextri.u32(i32 %aa, i32 2590)\n"
-      "  ret i32 %A\n"
-      "}\n"
-      "declare i32 @llvm.x86.tbm.bextri.u32(i32, i32)\n");
+  parseAssembly("define i32 @test(i32 %a) {\n"
+                "  %aa = or i32 %a, 4080\n"
+                "  %A = call i32 @llvm.x86.tbm.bextri.u32(i32 %aa, i32 2590)\n"
+                "  ret i32 %A\n"
+                "}\n"
+                "declare i32 @llvm.x86.tbm.bextri.u32(i32, i32)\n");
   expectKnownBits(/*zero*/ 0u, /*one*/ 0u);
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/199558


More information about the llvm-commits mailing list