[llvm] 021e6e0 - [instsimplify] Move (extelt (inselt Vec, Value, Index), Index) -> Value from InstCombine
Daniel Sanders via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 15:22:16 PDT 2022
Author: Daniel Sanders
Date: 2022-10-17T15:22:06-07:00
New Revision: 021e6e05d3d966d2291434fec1ec5d6db5633963
URL: https://github.com/llvm/llvm-project/commit/021e6e05d3d966d2291434fec1ec5d6db5633963
DIFF: https://github.com/llvm/llvm-project/commit/021e6e05d3d966d2291434fec1ec5d6db5633963.diff
LOG: [instsimplify] Move (extelt (inselt Vec, Value, Index), Index) -> Value from InstCombine
As requested in https://reviews.llvm.org/D135625#3858141
Differential Revision: https://reviews.llvm.org/D136099
Added:
llvm/test/Transforms/InstSimplify/vector-inseltextelt.ll
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Removed:
llvm/test/Transforms/InstCombine/vector-inseltextelt.ll
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index fe7b63c36128..acfac8cb9437 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4857,6 +4857,14 @@ static Value *simplifyExtractElementInst(Value *Vec, Value *Idx,
if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
return Elt;
} else {
+ // extractelt x, (insertelt y, elt, n), n -> elt
+ // If the possibly-variable indices are trivially known to be equal
+ // (because they are the same operand) then use the value that was
+ // inserted directly.
+ auto *IE = dyn_cast<InsertElementInst>(Vec);
+ if (IE && IE->getOperand(2) == Idx)
+ return IE->getOperand(1);
+
// The index is not relevant if our vector is a splat.
if (Value *Splat = getSplatValue(Vec))
return Splat;
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 9bb12cbd94f0..40acc2423a24 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -474,11 +474,6 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) {
if (auto *I = dyn_cast<Instruction>(SrcVec)) {
if (auto *IE = dyn_cast<InsertElementInst>(I)) {
- // If the possibly-variable indices are trivially known to be equal
- // (because they are the same operand) then use the value that was
- // inserted directly.
- if (IE->getOperand(2) == Index)
- return replaceInstUsesWith(EI, IE->getOperand(1));
// instsimplify already handled the case where the indices are constants
// and equal by value, if both are constants, they must not be the same
// value, extract from the pre-inserted value instead.
diff --git a/llvm/test/Transforms/InstCombine/vector-inseltextelt.ll b/llvm/test/Transforms/InstSimplify/vector-inseltextelt.ll
similarity index 93%
rename from llvm/test/Transforms/InstCombine/vector-inseltextelt.ll
rename to llvm/test/Transforms/InstSimplify/vector-inseltextelt.ll
index b0a6a4e25441..f7162965185b 100644
--- a/llvm/test/Transforms/InstCombine/vector-inseltextelt.ll
+++ b/llvm/test/Transforms/InstSimplify/vector-inseltextelt.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
; extracting a just-inserted element should yield the original value
define float @constant_index(<4 x float> %x, float %val) {
More information about the llvm-commits
mailing list