Skip to content

Instantly share code, notes, and snippets.

@nikic
Created May 31, 2022 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikic/d09ace51902e03e5b0cf04c528f87c49 to your computer and use it in GitHub Desktop.
Save nikic/d09ace51902e03e5b0cf04c528f87c49 to your computer and use it in GitHub Desktop.
commit a3393030cc79137c3defd1de9f31dd17bfa93d2a
Author: Nikita Popov <npopov@redhat.com>
Date: Tue May 31 17:20:48 2022 +0200
wip
diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
index 344f89e8ded1..4eb624e53d83 100644
--- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp
+++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
@@ -828,7 +828,10 @@ bool ScalarizerVisitor::visitExtractElementInst(ExtractElementInst &EEI) {
if (auto *CI = dyn_cast<ConstantInt>(ExtIdx)) {
Value *Res = Op0[CI->getValue().getZExtValue()];
- gather(&EEI, {Res});
+ if (Res != &EEI) {
+ EEI.replaceAllUsesWith(Res);
+ PotentiallyDeadInstrs.emplace_back(&EEI);
+ }
return true;
}
@@ -844,7 +847,10 @@ bool ScalarizerVisitor::visitExtractElementInst(ExtractElementInst &EEI) {
Res = Builder.CreateSelect(ShouldExtract, Elt, Res,
EEI.getName() + ".upto" + Twine(I));
}
- gather(&EEI, {Res});
+ if (Res != &EEI) {
+ EEI.replaceAllUsesWith(Res);
+ PotentiallyDeadInstrs.emplace_back(&EEI);
+ }
return true;
}
diff --git a/llvm/test/Transforms/Scalarizer/global-bug.ll b/llvm/test/Transforms/Scalarizer/global-bug.ll
index 91d1bd23af98..000ff59cb7f5 100644
--- a/llvm/test/Transforms/Scalarizer/global-bug.ll
+++ b/llvm/test/Transforms/Scalarizer/global-bug.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes='function(scalarizer)' -S | FileCheck %s
@a = dso_local global i16 0, align 1
@@ -10,6 +11,7 @@
define dso_local void @test1() local_unnamed_addr {
; CHECK-LABEL: @test1(
; CHECK-NEXT: entry:
+; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <4 x i16*> <i16* @a, i16* @a, i16* @a, i16* @a>, i32 1
; CHECK-NEXT: [[T0:%.*]] = ptrtoint i16* @a to i16
; CHECK-NEXT: store i16 [[T0]], i16* @b, align 1
; CHECK-NEXT: ret void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment