[llvm] [LLVM][Reassociate] Extend ConvertShiftToMul to allow for ConstantInt vectors. (PR #137340)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 25 07:33:23 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Paul Walker (paulwalker-arm)

<details>
<summary>Changes</summary>

This has the side effect of fixing the FIXME for when use-constant-int-for-fixed-length-splat becomes the default.

---
Full diff: https://github.com/llvm/llvm-project/pull/137340.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/Reassociate.cpp (+1-1) 
- (modified) llvm/test/Transforms/Reassociate/fast-ReassociateVector.ll (+11-5) 


``````````diff
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 8e478b37574f6..a8a11624be63f 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -1052,7 +1052,7 @@ static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
   // bitwidth - 1.
   bool NSW = cast<BinaryOperator>(Shl)->hasNoSignedWrap();
   bool NUW = cast<BinaryOperator>(Shl)->hasNoUnsignedWrap();
-  unsigned BitWidth = Shl->getType()->getIntegerBitWidth();
+  unsigned BitWidth = Shl->getType()->getScalarSizeInBits();
   if (NSW && (NUW || SA->getValue().ult(BitWidth - 1)))
     Mul->setHasNoSignedWrap(true);
   Mul->setHasNoUnsignedWrap(NUW);
diff --git a/llvm/test/Transforms/Reassociate/fast-ReassociateVector.ll b/llvm/test/Transforms/Reassociate/fast-ReassociateVector.ll
index 617d513f71268..d313164b8187a 100644
--- a/llvm/test/Transforms/Reassociate/fast-ReassociateVector.ll
+++ b/llvm/test/Transforms/Reassociate/fast-ReassociateVector.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes=reassociate -S | FileCheck %s
+; RUN: opt < %s -passes=reassociate -S | FileCheck %s --check-prefixes=CHECK,CHECK-CV
+; RUN: opt < %s -passes=reassociate -S -use-constant-int-for-fixed-length-splat | FileCheck %s --check-prefixes=CHECK,CHECK-CI
 
 ; Check that a*c+b*c is turned into (a+b)*c
 
@@ -370,10 +371,15 @@ define <2 x double> @test11_reassoc(<2 x double> %x, <2 x double> %y) {
 ; FIXME: shifts should be converted to mul to assist further reassociation.
 
 define <2 x i64> @test12(<2 x i64> %b, <2 x i64> %c) {
-; CHECK-LABEL: @test12(
-; CHECK-NEXT:    [[MUL:%.*]] = mul <2 x i64> [[C:%.*]], [[B:%.*]]
-; CHECK-NEXT:    [[SHL:%.*]] = shl <2 x i64> [[MUL]], splat (i64 5)
-; CHECK-NEXT:    ret <2 x i64> [[SHL]]
+; CHECK-CV-LABEL: @test12(
+; CHECK-CV-NEXT:    [[MUL:%.*]] = mul <2 x i64> [[C:%.*]], [[B:%.*]]
+; CHECK-CV-NEXT:    [[SHL:%.*]] = shl <2 x i64> [[MUL]], splat (i64 5)
+; CHECK-CV-NEXT:    ret <2 x i64> [[SHL]]
+;
+; CHECK-CI-LABEL: @test12(
+; CHECK-CI-NEXT:    [[MUL:%.*]] = mul <2 x i64> [[B:%.*]], splat (i64 32)
+; CHECK-CI-NEXT:    [[SHL:%.*]] = mul <2 x i64> [[MUL]], [[C:%.*]]
+; CHECK-CI-NEXT:    ret <2 x i64> [[SHL]]
 ;
   %mul = mul <2 x i64> %c, %b
   %shl = shl <2 x i64> %mul, <i64 5, i64 5>

``````````

</details>


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


More information about the llvm-commits mailing list