Skip to content

Commit 3b12bac

Browse files
[LLVM][Reassociate] Extend ConvertShiftToMul to allow for ConstantInt vectors. (llvm#137340)
This has the side effect of fixing the FIXME for when use-constant-int-for-fixed-length-splat becomes the default.
1 parent 5b20b57 commit 3b12bac

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

llvm/lib/Transforms/Scalar/Reassociate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
10521052
// bitwidth - 1.
10531053
bool NSW = cast<BinaryOperator>(Shl)->hasNoSignedWrap();
10541054
bool NUW = cast<BinaryOperator>(Shl)->hasNoUnsignedWrap();
1055-
unsigned BitWidth = Shl->getType()->getIntegerBitWidth();
1055+
unsigned BitWidth = Shl->getType()->getScalarSizeInBits();
10561056
if (NSW && (NUW || SA->getValue().ult(BitWidth - 1)))
10571057
Mul->setHasNoSignedWrap(true);
10581058
Mul->setHasNoUnsignedWrap(NUW);

llvm/test/Transforms/Reassociate/fast-ReassociateVector.ll

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -passes=reassociate -S | FileCheck %s
2+
; RUN: opt < %s -passes=reassociate -S | FileCheck %s --check-prefixes=CHECK,CHECK-CV
3+
; RUN: opt < %s -passes=reassociate -S -use-constant-int-for-fixed-length-splat | FileCheck %s --check-prefixes=CHECK,CHECK-CI
34

45
; Check that a*c+b*c is turned into (a+b)*c
56

@@ -370,10 +371,15 @@ define <2 x double> @test11_reassoc(<2 x double> %x, <2 x double> %y) {
370371
; FIXME: shifts should be converted to mul to assist further reassociation.
371372

372373
define <2 x i64> @test12(<2 x i64> %b, <2 x i64> %c) {
373-
; CHECK-LABEL: @test12(
374-
; CHECK-NEXT: [[MUL:%.*]] = mul <2 x i64> [[C:%.*]], [[B:%.*]]
375-
; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i64> [[MUL]], splat (i64 5)
376-
; CHECK-NEXT: ret <2 x i64> [[SHL]]
374+
; CHECK-CV-LABEL: @test12(
375+
; CHECK-CV-NEXT: [[MUL:%.*]] = mul <2 x i64> [[C:%.*]], [[B:%.*]]
376+
; CHECK-CV-NEXT: [[SHL:%.*]] = shl <2 x i64> [[MUL]], splat (i64 5)
377+
; CHECK-CV-NEXT: ret <2 x i64> [[SHL]]
378+
;
379+
; CHECK-CI-LABEL: @test12(
380+
; CHECK-CI-NEXT: [[MUL:%.*]] = mul <2 x i64> [[B:%.*]], splat (i64 32)
381+
; CHECK-CI-NEXT: [[SHL:%.*]] = mul <2 x i64> [[MUL]], [[C:%.*]]
382+
; CHECK-CI-NEXT: ret <2 x i64> [[SHL]]
377383
;
378384
%mul = mul <2 x i64> %c, %b
379385
%shl = shl <2 x i64> %mul, <i64 5, i64 5>

0 commit comments

Comments
 (0)