[llvm] dbf3b5f - [InstCombine] fold more shuffles with FP<->Int cast operands
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue May 17 11:25:17 PDT 2022
Author: Sanjay Patel
Date: 2022-05-17T14:25:11-04:00
New Revision: dbf3b5f114553e4d5a446cd9ef57e98a8d04354e
URL: https://github.com/llvm/llvm-project/commit/dbf3b5f114553e4d5a446cd9ef57e98a8d04354e
DIFF: https://github.com/llvm/llvm-project/commit/dbf3b5f114553e4d5a446cd9ef57e98a8d04354e.diff
LOG: [InstCombine] fold more shuffles with FP<->Int cast operands
shuffle (cast X), (cast Y), Mask --> cast (shuffle X, Y, Mask)
This extends the transform added with 0353c2c996c5.
If the casts are to a larger element type, the transform
reduces shuffle bit width, so that should be a win for
most codegen (if not, it can be inverted).
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/test/Transforms/InstCombine/vec_shuffle.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 1e8165526d85..c5bdfa43f749 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2306,10 +2306,10 @@ static Instruction *foldCastShuffle(ShuffleVectorInst &Shuf,
if (ShufTy != ShufOpTy)
return nullptr;
- // TODO: Allow element-size-changing casts?
+ // TODO: Allow element-size-decreasing casts (ex: fptosi float to i8)?
assert(isa<FixedVectorType>(CastSrcTy) && isa<FixedVectorType>(ShufOpTy) &&
"Expected fixed vector operands for casts and binary shuffle");
- if (CastSrcTy->getPrimitiveSizeInBits() != ShufOpTy->getPrimitiveSizeInBits())
+ if (CastSrcTy->getPrimitiveSizeInBits() > ShufOpTy->getPrimitiveSizeInBits())
return nullptr;
// At least one of the operands must have only one use (the shuffle).
diff --git a/llvm/test/Transforms/InstCombine/vec_shuffle.ll b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
index 746966a2e13d..20dab18266d0 100644
--- a/llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -2079,9 +2079,8 @@ define <3 x i16> @fptoui_shuf_
diff erent_source_types(<3 x float> %x, <3 x half>
define <4 x i32> @fptoui_shuf_widen_elts(<4 x half> %x, <4 x half> %y) {
; CHECK-LABEL: @fptoui_shuf_widen_elts(
-; CHECK-NEXT: [[NX:%.*]] = fptosi <4 x half> [[X:%.*]] to <4 x i32>
-; CHECK-NEXT: [[NY:%.*]] = fptosi <4 x half> [[Y:%.*]] to <4 x i32>
-; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i32> [[NX]], <4 x i32> [[NY]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x half> [[X:%.*]], <4 x half> [[Y:%.*]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
+; CHECK-NEXT: [[R:%.*]] = fptosi <4 x half> [[TMP1]] to <4 x i32>
; CHECK-NEXT: ret <4 x i32> [[R]]
;
%nx = fptosi <4 x half> %x to <4 x i32>
More information about the llvm-commits
mailing list