[llvm] 3b12bac - [LLVM][Reassociate] Extend ConvertShiftToMul to allow for ConstantInt vectors. (#137340)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 30 05:41:43 PDT 2025
Author: Paul Walker
Date: 2025-04-30T13:41:40+01:00
New Revision: 3b12bac6d1b3ac8aa4b465abe5adec8110025fac
URL: https://github.com/llvm/llvm-project/commit/3b12bac6d1b3ac8aa4b465abe5adec8110025fac
DIFF: https://github.com/llvm/llvm-project/commit/3b12bac6d1b3ac8aa4b465abe5adec8110025fac.diff
LOG: [LLVM][Reassociate] Extend ConvertShiftToMul to allow for ConstantInt vectors. (#137340)
This has the side effect of fixing the FIXME for when
use-constant-int-for-fixed-length-splat becomes the default.
Added:
Modified:
llvm/lib/Transforms/Scalar/Reassociate.cpp
llvm/test/Transforms/Reassociate/fast-ReassociateVector.ll
Removed:
################################################################################
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>
More information about the llvm-commits
mailing list