[llvm] [AutoUpgrade] Prevent deletion of call if uses still exist (PR #177606)
Kshitij Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 2 10:47:13 PST 2026
https://github.com/kshitijvp updated https://github.com/llvm/llvm-project/pull/177606
>From 7a06e21a6f708344429f53166d3f3dadce251b5e Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Fri, 23 Jan 2026 21:16:56 +0530
Subject: [PATCH 01/19] [AutoUpgrade] Prevent deletion of call if uses still
exist
The calls to the llvm.x86.sse2.pshuflw are being
deleted due to invalid vector type, even though
uses still exist. Adding checks to prevent deletion
of call when uses still exist or even if eraseFromParent()
is called ensuring it is called after replaceAllUsesWith().
---
llvm/lib/IR/AutoUpgrade.cpp | 7 ++++---
llvm/test/Verifier/issue176674.ll | 13 +++++++++++++
2 files changed, 17 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/Verifier/issue176674.ll
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 562114c355f9e..64d0b339009cb 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4944,9 +4944,10 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
llvm_unreachable("Unknown function for CallBase upgrade.");
}
- if (Rep)
+ if (Rep) {
CI->replaceAllUsesWith(Rep);
- CI->eraseFromParent();
+ CI->eraseFromParent();
+ }
return;
}
@@ -5668,7 +5669,7 @@ void llvm::UpgradeCallsToIntrinsic(Function *F) {
UpgradeIntrinsicCall(CB, NewFn);
// Remove old function, no longer used, from the module.
- if (F != NewFn)
+ if (NewFn != nullptr && F != NewFn)
F->eraseFromParent();
}
}
diff --git a/llvm/test/Verifier/issue176674.ll b/llvm/test/Verifier/issue176674.ll
new file mode 100644
index 0000000000000..349950b143fa2
--- /dev/null
+++ b/llvm/test/Verifier/issue176674.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt < %s -passes=verify -S | FileCheck %s
+define void @test(ptr %a) {
+; CHECK-LABEL: define void @test(
+; CHECK-SAME: ptr [[A:%.*]]) {
+; CHECK-NEXT: [[V:%.*]] = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
+; CHECK-NEXT: store <4 x i32> [[V]], ptr [[A]], align 16
+; CHECK-NEXT: ret void
+;
+ %v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
+ store <4 x i32> %v, ptr %a
+ ret void
+}
>From c138552e8ca609932ef09f7c2401437b632157ea Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Fri, 30 Jan 2026 14:18:33 +0530
Subject: [PATCH 02/19] Added case when no intrinsics match
Added case when provided intrinsics does
not match any of the standard llvm intrinsics.
Also when pshufl.w was called with invalid
intrinsic signature it caused assertion failure
idx < size. Handled this case by reportFatalUsageError.
---
llvm/lib/IR/AutoUpgrade.cpp | 53 ++++++++++++++++-------------
llvm/test/Verifier/issue176674.ll | 11 ++----
llvm/test/Verifier/issue176674_1.ll | 8 +++++
3 files changed, 40 insertions(+), 32 deletions(-)
create mode 100644 llvm/test/Verifier/issue176674_1.ll
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 64d0b339009cb..4cdda02cc499c 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -3022,7 +3022,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Intrinsic::ID IID;
switch (VecWidth) {
default:
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
case 128:
IID = Intrinsic::x86_avx512_vpshufbitqmb_128;
break;
@@ -3055,7 +3055,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_fpclass_pd_512;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
Rep =
Builder.CreateIntrinsic(IID, {CI->getOperand(0), CI->getArgOperand(1)});
@@ -3079,7 +3079,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
Value *Mask = Constant::getAllOnesValue(CI->getType());
if (VecWidth == 512)
@@ -3249,7 +3249,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Name.ends_with("d") || Name.ends_with("q"))
IsSigned = true;
else
- llvm_unreachable("Unknown suffix");
+ reportFatalUsageError("Unknown suffix");
unsigned Imm;
if (CI->arg_size() == 3) {
@@ -3622,6 +3622,9 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Op0 = CI->getArgOperand(0);
unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
unsigned NumElts = cast<FixedVectorType>(CI->getType())->getNumElements();
+
+ if (Name == "sse2.pshufl.w" && NumElts % 8 != 0)
+ reportFatalUsageError("Invalid Intrinsic Signature");
SmallVector<int, 16> Idxs(NumElts);
for (unsigned l = 0; l != NumElts; l += 8) {
@@ -3893,7 +3896,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psllv32hi
IID = Intrinsic::x86_avx512_psllv_w_512;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psll.d.128, avx512.mask.psll.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_pslli_d
@@ -3905,7 +3908,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_pslli_w
: Intrinsic::x86_sse2_psll_w;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psll.d.256, avx512.mask.psll.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_pslli_d
@@ -3917,7 +3920,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_pslli_w
: Intrinsic::x86_avx2_psll_w;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else {
if (Size == 'd') // psll.di.512, pslli.d, psll.d, psllv.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_pslli_d_512
@@ -3931,7 +3934,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_pslli_w_512
: Intrinsic::x86_avx512_psll_w_512;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -3960,7 +3963,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psrlv32hi
IID = Intrinsic::x86_avx512_psrlv_w_512;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psrl.d.128, avx512.mask.psrl.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_psrli_d
@@ -3972,7 +3975,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_psrli_w
: Intrinsic::x86_sse2_psrl_w;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psrl.d.256, avx512.mask.psrl.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_psrli_d
@@ -3984,7 +3987,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_psrli_w
: Intrinsic::x86_avx2_psrl_w;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else {
if (Size == 'd') // psrl.di.512, psrli.d, psrl.d, psrl.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_psrli_d_512
@@ -3998,7 +4001,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_psrli_w_512
: Intrinsic::x86_avx512_psrl_w_512;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -4023,7 +4026,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psrav32hi
IID = Intrinsic::x86_avx512_psrav_w_512;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psra.d.128, avx512.mask.psra.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_psrai_d
@@ -4036,7 +4039,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_psrai_w
: Intrinsic::x86_sse2_psra_w;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psra.d.256, avx512.mask.psra.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_psrai_d
@@ -4049,7 +4052,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_psrai_w
: Intrinsic::x86_avx2_psra_w;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
} else {
if (Size == 'd') // psra.di.512, psrai.d, psra.d, psrav.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_psrai_d_512
@@ -4063,7 +4066,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_psrai_w_512
: Intrinsic::x86_avx512_psra_w_512;
else
- llvm_unreachable("Unexpected size");
+ reportFatalUsageError("Unexpected size");
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -4232,7 +4235,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 256 && EltWidth == 64)
IID = Intrinsic::x86_fma_vfmaddsub_pd_256;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4307,7 +4310,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_pternlog_q_512;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2), CI->getArgOperand(3)};
@@ -4334,7 +4337,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && High)
IID = Intrinsic::x86_avx512_vpmadd52h_uq_512;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4369,7 +4372,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpbusds_512;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4393,7 +4396,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt8Ty(), 64, false);
else
- llvm_unreachable("Unexpected vector bit width");
+ reportFatalUsageError("Unexpected vector bit width");
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4424,7 +4427,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpwssds_512;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4448,7 +4451,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt16Ty(), 32, false);
else
- llvm_unreachable("Unexpected vector bit width");
+ reportFatalUsageError("Unexpected vector bit width");
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4471,7 +4474,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[0] == 's' && Name.back() == '4')
IID = Intrinsic::x86_subborrow_64;
else
- llvm_unreachable("Unexpected intrinsic");
+ reportFatalUsageError("Unexpected intrinsic");
// Make a call with 3 operands.
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
@@ -4490,6 +4493,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
upgradeAVX512MaskToSelect(Name, Builder, *CI, Rep)) {
// Rep will be updated by the call in the condition.
}
+ else
+ reportFatalUsageError("Invalid Intrinsic Used");
return Rep;
}
diff --git a/llvm/test/Verifier/issue176674.ll b/llvm/test/Verifier/issue176674.ll
index 349950b143fa2..5873a596ee84a 100644
--- a/llvm/test/Verifier/issue176674.ll
+++ b/llvm/test/Verifier/issue176674.ll
@@ -1,12 +1,7 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; RUN: opt < %s -passes=verify -S | FileCheck %s
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+; CHECK: LLVM ERROR: Invalid Intrinsic Used
+
define void @test(ptr %a) {
-; CHECK-LABEL: define void @test(
-; CHECK-SAME: ptr [[A:%.*]]) {
-; CHECK-NEXT: [[V:%.*]] = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
-; CHECK-NEXT: store <4 x i32> [[V]], ptr [[A]], align 16
-; CHECK-NEXT: ret void
-;
%v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
store <4 x i32> %v, ptr %a
ret void
diff --git a/llvm/test/Verifier/issue176674_1.ll b/llvm/test/Verifier/issue176674_1.ll
new file mode 100644
index 0000000000000..886c4b1b2f111
--- /dev/null
+++ b/llvm/test/Verifier/issue176674_1.ll
@@ -0,0 +1,8 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+; CHECK: LLVM ERROR: Invalid Intrinsic Signature
+
+define void @test(ptr %a) {
+ %v = call <4 x i32> @llvm.x86.sse2.pshufl.w(<4 x i32> zeroinitializer, i8 0)
+ store <4 x i32> %v, ptr %a
+ ret void
+}
>From c72b33867e423fff7c08ae77a94287faa231d019 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Fri, 30 Jan 2026 14:30:38 +0530
Subject: [PATCH 03/19] Nitpick
---
llvm/lib/IR/AutoUpgrade.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 4cdda02cc499c..0145fd0dc9ad1 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -3622,7 +3622,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Value *Op0 = CI->getArgOperand(0);
unsigned Imm = cast<ConstantInt>(CI->getArgOperand(1))->getZExtValue();
unsigned NumElts = cast<FixedVectorType>(CI->getType())->getNumElements();
-
+
if (Name == "sse2.pshufl.w" && NumElts % 8 != 0)
reportFatalUsageError("Invalid Intrinsic Signature");
@@ -4492,8 +4492,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name.starts_with("avx512.mask.") &&
upgradeAVX512MaskToSelect(Name, Builder, *CI, Rep)) {
// Rep will be updated by the call in the condition.
- }
- else
+ } else
reportFatalUsageError("Invalid Intrinsic Used");
return Rep;
@@ -4951,8 +4950,8 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
if (Rep) {
CI->replaceAllUsesWith(Rep);
- CI->eraseFromParent();
}
+ CI->eraseFromParent();
return;
}
@@ -5674,7 +5673,7 @@ void llvm::UpgradeCallsToIntrinsic(Function *F) {
UpgradeIntrinsicCall(CB, NewFn);
// Remove old function, no longer used, from the module.
- if (NewFn != nullptr && F != NewFn)
+ if (F != NewFn)
F->eraseFromParent();
}
}
>From a06bbef2d0f100932d8193243591682e9637856e Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Fri, 30 Jan 2026 14:32:14 +0530
Subject: [PATCH 04/19] Nitpick
---
llvm/lib/IR/AutoUpgrade.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 0145fd0dc9ad1..09d94552a7091 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4948,9 +4948,8 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
llvm_unreachable("Unknown function for CallBase upgrade.");
}
- if (Rep) {
+ if (Rep)
CI->replaceAllUsesWith(Rep);
- }
CI->eraseFromParent();
return;
}
>From 8853c3adc517ef578b36f9e7ab8024ef3f8f104f Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 00:12:50 +0530
Subject: [PATCH 05/19] Added new helper function to print CallInst
---
llvm/lib/IR/AutoUpgrade.cpp | 60 ++++++++++++++++-------------
llvm/test/Verifier/issue176674.ll | 3 +-
llvm/test/Verifier/issue176674_1.ll | 3 +-
3 files changed, 38 insertions(+), 28 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 09d94552a7091..fabd694867525 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -47,6 +47,7 @@
#include "llvm/Support/AMDGPUAddrSpace.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/NVPTXAddrSpace.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/TimeProfiler.h"
@@ -63,6 +64,13 @@ static cl::opt<bool>
static void rename(GlobalValue *GV) { GV->setName(GV->getName() + ".old"); }
+// Report a fatal error along with the
+// Call Instruction which caused the error
+static void reportFatalUsageErrorWithCI(StringRef reason, CallBase* CI) {
+ CI->dump();
+ reportFatalUsageError(reason);
+}
+
// Upgrade the declarations of the SSE4.1 ptest intrinsics whose arguments have
// changed their type from v4f32 to v2i64.
static bool upgradePTESTIntrinsic(Function *F, Intrinsic::ID IID,
@@ -3022,7 +3030,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Intrinsic::ID IID;
switch (VecWidth) {
default:
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
case 128:
IID = Intrinsic::x86_avx512_vpshufbitqmb_128;
break;
@@ -3055,7 +3063,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_fpclass_pd_512;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
Rep =
Builder.CreateIntrinsic(IID, {CI->getOperand(0), CI->getArgOperand(1)});
@@ -3079,7 +3087,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
Value *Mask = Constant::getAllOnesValue(CI->getType());
if (VecWidth == 512)
@@ -3249,7 +3257,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Name.ends_with("d") || Name.ends_with("q"))
IsSigned = true;
else
- reportFatalUsageError("Unknown suffix");
+ reportFatalUsageErrorWithCI("Above intrinsic has unknown suffix", CI);
unsigned Imm;
if (CI->arg_size() == 3) {
@@ -3624,7 +3632,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
unsigned NumElts = cast<FixedVectorType>(CI->getType())->getNumElements();
if (Name == "sse2.pshufl.w" && NumElts % 8 != 0)
- reportFatalUsageError("Invalid Intrinsic Signature");
+ reportFatalUsageErrorWithCI("Above intrinsic has invalid signature", CI);
SmallVector<int, 16> Idxs(NumElts);
for (unsigned l = 0; l != NumElts; l += 8) {
@@ -3896,7 +3904,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psllv32hi
IID = Intrinsic::x86_avx512_psllv_w_512;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psll.d.128, avx512.mask.psll.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_pslli_d
@@ -3908,7 +3916,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_pslli_w
: Intrinsic::x86_sse2_psll_w;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psll.d.256, avx512.mask.psll.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_pslli_d
@@ -3920,7 +3928,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_pslli_w
: Intrinsic::x86_avx2_psll_w;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else {
if (Size == 'd') // psll.di.512, pslli.d, psll.d, psllv.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_pslli_d_512
@@ -3934,7 +3942,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_pslli_w_512
: Intrinsic::x86_avx512_psll_w_512;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -3963,7 +3971,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psrlv32hi
IID = Intrinsic::x86_avx512_psrlv_w_512;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psrl.d.128, avx512.mask.psrl.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_psrli_d
@@ -3975,7 +3983,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_psrli_w
: Intrinsic::x86_sse2_psrl_w;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psrl.d.256, avx512.mask.psrl.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_psrli_d
@@ -3987,7 +3995,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_psrli_w
: Intrinsic::x86_avx2_psrl_w;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else {
if (Size == 'd') // psrl.di.512, psrli.d, psrl.d, psrl.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_psrli_d_512
@@ -4001,7 +4009,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_psrli_w_512
: Intrinsic::x86_avx512_psrl_w_512;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -4026,7 +4034,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psrav32hi
IID = Intrinsic::x86_avx512_psrav_w_512;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psra.d.128, avx512.mask.psra.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_psrai_d
@@ -4039,7 +4047,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_psrai_w
: Intrinsic::x86_sse2_psra_w;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psra.d.256, avx512.mask.psra.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_psrai_d
@@ -4052,7 +4060,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_psrai_w
: Intrinsic::x86_avx2_psra_w;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
} else {
if (Size == 'd') // psra.di.512, psrai.d, psra.d, psrav.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_psrai_d_512
@@ -4066,7 +4074,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_psrai_w_512
: Intrinsic::x86_avx512_psra_w_512;
else
- reportFatalUsageError("Unexpected size");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -4235,7 +4243,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 256 && EltWidth == 64)
IID = Intrinsic::x86_fma_vfmaddsub_pd_256;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4310,7 +4318,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_pternlog_q_512;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2), CI->getArgOperand(3)};
@@ -4337,7 +4345,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && High)
IID = Intrinsic::x86_avx512_vpmadd52h_uq_512;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4372,7 +4380,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpbusds_512;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4396,7 +4404,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt8Ty(), 64, false);
else
- reportFatalUsageError("Unexpected vector bit width");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected vector bit width", CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4427,7 +4435,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpwssds_512;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4451,7 +4459,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt16Ty(), 32, false);
else
- reportFatalUsageError("Unexpected vector bit width");
+ reportFatalUsageErrorWithCI("Above intrinsic has unexpected vector bit width", CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4474,7 +4482,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[0] == 's' && Name.back() == '4')
IID = Intrinsic::x86_subborrow_64;
else
- reportFatalUsageError("Unexpected intrinsic");
+ reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
// Make a call with 3 operands.
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
@@ -4493,7 +4501,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
upgradeAVX512MaskToSelect(Name, Builder, *CI, Rep)) {
// Rep will be updated by the call in the condition.
} else
- reportFatalUsageError("Invalid Intrinsic Used");
+ reportFatalUsageErrorWithCI("Above intrinsic is invalid", CI);
return Rep;
}
diff --git a/llvm/test/Verifier/issue176674.ll b/llvm/test/Verifier/issue176674.ll
index 5873a596ee84a..95267a7072426 100644
--- a/llvm/test/Verifier/issue176674.ll
+++ b/llvm/test/Verifier/issue176674.ll
@@ -1,5 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
-; CHECK: LLVM ERROR: Invalid Intrinsic Used
+; CHECK: %v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
+; CHECK: LLVM ERROR: Above intrinsic is invalid
define void @test(ptr %a) {
%v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
diff --git a/llvm/test/Verifier/issue176674_1.ll b/llvm/test/Verifier/issue176674_1.ll
index 886c4b1b2f111..0aff7090c5ae6 100644
--- a/llvm/test/Verifier/issue176674_1.ll
+++ b/llvm/test/Verifier/issue176674_1.ll
@@ -1,5 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
-; CHECK: LLVM ERROR: Invalid Intrinsic Signature
+; CHECK: %v = call <4 x i32> @llvm.x86.sse2.pshufl.w(<4 x i32> zeroinitializer, i8 0)
+; CHECK: LLVM ERROR: Above intrinsic has invalid signature
define void @test(ptr %a) {
%v = call <4 x i32> @llvm.x86.sse2.pshufl.w(<4 x i32> zeroinitializer, i8 0)
>From a22128ea589b02daa0fb8adec45bf5d756fbf45d Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 00:19:57 +0530
Subject: [PATCH 06/19] Nitpick
---
llvm/lib/IR/AutoUpgrade.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index fabd694867525..2724ab555cf30 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -47,7 +47,6 @@
#include "llvm/Support/AMDGPUAddrSpace.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/NVPTXAddrSpace.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/TimeProfiler.h"
@@ -65,8 +64,8 @@ static cl::opt<bool>
static void rename(GlobalValue *GV) { GV->setName(GV->getName() + ".old"); }
// Report a fatal error along with the
-// Call Instruction which caused the error
-static void reportFatalUsageErrorWithCI(StringRef reason, CallBase* CI) {
+// Call Instruction which caused the error
+static void reportFatalUsageErrorWithCI(StringRef reason, CallBase *CI) {
CI->dump();
reportFatalUsageError(reason);
}
@@ -4404,7 +4403,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt8Ty(), 64, false);
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected vector bit width", CI);
+ reportFatalUsageErrorWithCI(
+ "Above intrinsic has unexpected vector bit width", CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4459,7 +4459,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt16Ty(), 32, false);
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected vector bit width", CI);
+ reportFatalUsageErrorWithCI(
+ "Above intrinsic has unexpected vector bit width", CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
>From 3d75aecfdb177fe020db6094fe8b44c41737fa87 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 00:51:28 +0530
Subject: [PATCH 07/19] Fix verifier crash
---
llvm/lib/IR/AutoUpgrade.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 2724ab555cf30..23e75520a87dc 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -3030,6 +3030,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
switch (VecWidth) {
default:
reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ break;
case 128:
IID = Intrinsic::x86_avx512_vpshufbitqmb_128;
break;
>From f8fece091e3f50c8cdcaaa04b52d5e2599bf5991 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 01:52:34 +0530
Subject: [PATCH 08/19] Initialize IID
---
llvm/lib/IR/AutoUpgrade.cpp | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 23e75520a87dc..cdf894c6e3880 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -4021,7 +4021,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
: Name[18] == '.' ? Name[19]
: Name[20];
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (IsVariable && Name[17] != '.') {
if (Size == 's' && Name[17] == '4') // avx512.mask.psrav4.si
IID = Intrinsic::x86_avx2_psrav_d;
@@ -4233,7 +4233,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name.starts_with("fma.vfmsubadd.p")) {
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
unsigned EltWidth = CI->getType()->getScalarSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_fma_vfmaddsub_ps;
else if (VecWidth == 256 && EltWidth == 32)
@@ -4304,7 +4304,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
unsigned EltWidth = CI->getType()->getScalarSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_avx512_pternlog_d_128;
else if (VecWidth == 256 && EltWidth == 32)
@@ -4331,7 +4331,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
bool High = Name[20] == 'h' || Name[21] == 'h';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (VecWidth == 128 && !High)
IID = Intrinsic::x86_avx512_vpmadd52l_uq_128;
else if (VecWidth == 256 && !High)
@@ -4366,7 +4366,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
bool IsSaturating = Name[ZeroMask ? 21 : 20] == 's';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (VecWidth == 128 && !IsSaturating)
IID = Intrinsic::x86_avx512_vpdpbusd_128;
else if (VecWidth == 256 && !IsSaturating)
@@ -4422,7 +4422,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
bool IsSaturating = Name[ZeroMask ? 21 : 20] == 's';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (VecWidth == 128 && !IsSaturating)
IID = Intrinsic::x86_avx512_vpdpwssd_128;
else if (VecWidth == 256 && !IsSaturating)
@@ -4474,7 +4474,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name == "addcarryx.u32" || Name == "addcarryx.u64" ||
Name == "addcarry.u32" || Name == "addcarry.u64" ||
Name == "subborrow.u32" || Name == "subborrow.u64") {
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (Name[0] == 'a' && Name.back() == '2')
IID = Intrinsic::x86_addcarry_32;
else if (Name[0] == 'a' && Name.back() == '4')
>From 54766a01792b6126fd264519918d781caf1d5b36 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 02:06:10 +0530
Subject: [PATCH 09/19] nitpick
---
llvm/lib/IR/AutoUpgrade.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index cdf894c6e3880..31c1bf710d785 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -3026,7 +3026,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name.starts_with("avx512.mask.vpshufbitqmb.")) {
Type *OpTy = CI->getArgOperand(0)->getType();
unsigned VecWidth = OpTy->getPrimitiveSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
switch (VecWidth) {
default:
reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
@@ -3049,7 +3049,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Type *OpTy = CI->getArgOperand(0)->getType();
unsigned VecWidth = OpTy->getPrimitiveSizeInBits();
unsigned EltWidth = OpTy->getScalarSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_avx512_fpclass_ps_128;
else if (VecWidth == 256 && EltWidth == 32)
@@ -3073,7 +3073,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Type *OpTy = Args[0]->getType();
unsigned VecWidth = OpTy->getPrimitiveSizeInBits();
unsigned EltWidth = OpTy->getScalarSizeInBits();
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_avx512_mask_cmp_ps_128;
else if (VecWidth == 256 && EltWidth == 32)
@@ -3887,7 +3887,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
: Name[18] == '.' ? Name[19]
: Name[20];
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (IsVariable && Name[17] != '.') {
if (Size == 'd' && Name[17] == '2') // avx512.mask.psllv2.di
IID = Intrinsic::x86_avx2_psllv_q;
@@ -3954,7 +3954,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
: Name[18] == '.' ? Name[19]
: Name[20];
- Intrinsic::ID IID;
+ Intrinsic::ID IID = 0;
if (IsVariable && Name[17] != '.') {
if (Size == 'd' && Name[17] == '2') // avx512.mask.psrlv2.di
IID = Intrinsic::x86_avx2_psrlv_q;
>From dab1712b93117bb2e4ca41dbd04c5970c40a156a Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 12:03:25 +0530
Subject: [PATCH 10/19] Fix verifier crash
---
llvm/lib/IR/AutoUpgrade.cpp | 78 ++++++++++++++++++-------------------
1 file changed, 39 insertions(+), 39 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 31c1bf710d785..13c2d910198c4 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -65,7 +65,7 @@ static void rename(GlobalValue *GV) { GV->setName(GV->getName() + ".old"); }
// Report a fatal error along with the
// Call Instruction which caused the error
-static void reportFatalUsageErrorWithCI(StringRef reason, CallBase *CI) {
+[[noreturn]] static void reportFatalUsageErrorWithCI(StringRef reason, CallBase *CI) {
CI->dump();
reportFatalUsageError(reason);
}
@@ -3026,10 +3026,10 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name.starts_with("avx512.mask.vpshufbitqmb.")) {
Type *OpTy = CI->getArgOperand(0)->getType();
unsigned VecWidth = OpTy->getPrimitiveSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
switch (VecWidth) {
default:
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
break;
case 128:
IID = Intrinsic::x86_avx512_vpshufbitqmb_128;
@@ -3049,7 +3049,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Type *OpTy = CI->getArgOperand(0)->getType();
unsigned VecWidth = OpTy->getPrimitiveSizeInBits();
unsigned EltWidth = OpTy->getScalarSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_avx512_fpclass_ps_128;
else if (VecWidth == 256 && EltWidth == 32)
@@ -3063,7 +3063,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_fpclass_pd_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
Rep =
Builder.CreateIntrinsic(IID, {CI->getOperand(0), CI->getArgOperand(1)});
@@ -3073,7 +3073,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Type *OpTy = Args[0]->getType();
unsigned VecWidth = OpTy->getPrimitiveSizeInBits();
unsigned EltWidth = OpTy->getScalarSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_avx512_mask_cmp_ps_128;
else if (VecWidth == 256 && EltWidth == 32)
@@ -3087,7 +3087,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
Value *Mask = Constant::getAllOnesValue(CI->getType());
if (VecWidth == 512)
@@ -3257,7 +3257,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Name.ends_with("d") || Name.ends_with("q"))
IsSigned = true;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unknown suffix", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unknown suffix", CI);
unsigned Imm;
if (CI->arg_size() == 3) {
@@ -3632,7 +3632,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
unsigned NumElts = cast<FixedVectorType>(CI->getType())->getNumElements();
if (Name == "sse2.pshufl.w" && NumElts % 8 != 0)
- reportFatalUsageErrorWithCI("Above intrinsic has invalid signature", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has invalid signature", CI);
SmallVector<int, 16> Idxs(NumElts);
for (unsigned l = 0; l != NumElts; l += 8) {
@@ -3887,7 +3887,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
: Name[18] == '.' ? Name[19]
: Name[20];
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (IsVariable && Name[17] != '.') {
if (Size == 'd' && Name[17] == '2') // avx512.mask.psllv2.di
IID = Intrinsic::x86_avx2_psllv_q;
@@ -3904,7 +3904,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psllv32hi
IID = Intrinsic::x86_avx512_psllv_w_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psll.d.128, avx512.mask.psll.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_pslli_d
@@ -3916,7 +3916,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_pslli_w
: Intrinsic::x86_sse2_psll_w;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psll.d.256, avx512.mask.psll.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_pslli_d
@@ -3928,7 +3928,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_pslli_w
: Intrinsic::x86_avx2_psll_w;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else {
if (Size == 'd') // psll.di.512, pslli.d, psll.d, psllv.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_pslli_d_512
@@ -3942,7 +3942,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_pslli_w_512
: Intrinsic::x86_avx512_psll_w_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -3954,7 +3954,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
: Name[18] == '.' ? Name[19]
: Name[20];
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (IsVariable && Name[17] != '.') {
if (Size == 'd' && Name[17] == '2') // avx512.mask.psrlv2.di
IID = Intrinsic::x86_avx2_psrlv_q;
@@ -3971,7 +3971,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psrlv32hi
IID = Intrinsic::x86_avx512_psrlv_w_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psrl.d.128, avx512.mask.psrl.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_psrli_d
@@ -3983,7 +3983,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_psrli_w
: Intrinsic::x86_sse2_psrl_w;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psrl.d.256, avx512.mask.psrl.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_psrli_d
@@ -3995,7 +3995,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_psrli_w
: Intrinsic::x86_avx2_psrl_w;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else {
if (Size == 'd') // psrl.di.512, psrli.d, psrl.d, psrl.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_psrli_d_512
@@ -4009,7 +4009,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_psrli_w_512
: Intrinsic::x86_avx512_psrl_w_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -4021,7 +4021,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
: Name[18] == '.' ? Name[19]
: Name[20];
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (IsVariable && Name[17] != '.') {
if (Size == 's' && Name[17] == '4') // avx512.mask.psrav4.si
IID = Intrinsic::x86_avx2_psrav_d;
@@ -4034,7 +4034,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[17] == '3' && Name[18] == '2') // avx512.mask.psrav32hi
IID = Intrinsic::x86_avx512_psrav_w_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else if (Name.ends_with(".128")) {
if (Size == 'd') // avx512.mask.psra.d.128, avx512.mask.psra.di.128
IID = IsImmediate ? Intrinsic::x86_sse2_psrai_d
@@ -4047,7 +4047,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_sse2_psrai_w
: Intrinsic::x86_sse2_psra_w;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else if (Name.ends_with(".256")) {
if (Size == 'd') // avx512.mask.psra.d.256, avx512.mask.psra.di.256
IID = IsImmediate ? Intrinsic::x86_avx2_psrai_d
@@ -4060,7 +4060,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx2_psrai_w
: Intrinsic::x86_avx2_psra_w;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
} else {
if (Size == 'd') // psra.di.512, psrai.d, psra.d, psrav.d.512
IID = IsImmediate ? Intrinsic::x86_avx512_psrai_d_512
@@ -4074,7 +4074,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
IID = IsImmediate ? Intrinsic::x86_avx512_psrai_w_512
: Intrinsic::x86_avx512_psra_w_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic has unexpected size", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected size", CI);
}
Rep = upgradeX86MaskedShift(Builder, *CI, IID);
@@ -4233,7 +4233,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name.starts_with("fma.vfmsubadd.p")) {
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
unsigned EltWidth = CI->getType()->getScalarSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_fma_vfmaddsub_ps;
else if (VecWidth == 256 && EltWidth == 32)
@@ -4243,7 +4243,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 256 && EltWidth == 64)
IID = Intrinsic::x86_fma_vfmaddsub_pd_256;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4304,7 +4304,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
unsigned EltWidth = CI->getType()->getScalarSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (VecWidth == 128 && EltWidth == 32)
IID = Intrinsic::x86_avx512_pternlog_d_128;
else if (VecWidth == 256 && EltWidth == 32)
@@ -4318,7 +4318,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_pternlog_q_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2), CI->getArgOperand(3)};
@@ -4331,7 +4331,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
bool High = Name[20] == 'h' || Name[21] == 'h';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (VecWidth == 128 && !High)
IID = Intrinsic::x86_avx512_vpmadd52l_uq_128;
else if (VecWidth == 256 && !High)
@@ -4345,7 +4345,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && High)
IID = Intrinsic::x86_avx512_vpmadd52h_uq_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4366,7 +4366,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
bool IsSaturating = Name[ZeroMask ? 21 : 20] == 's';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (VecWidth == 128 && !IsSaturating)
IID = Intrinsic::x86_avx512_vpdpbusd_128;
else if (VecWidth == 256 && !IsSaturating)
@@ -4380,7 +4380,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpbusds_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4405,7 +4405,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
NewArgType = VectorType::get(Builder.getInt8Ty(), 64, false);
else
reportFatalUsageErrorWithCI(
- "Above intrinsic has unexpected vector bit width", CI);
+ "Intrinsic has unexpected vector bit width", CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4422,7 +4422,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
bool ZeroMask = Name[11] == 'z';
bool IsSaturating = Name[ZeroMask ? 21 : 20] == 's';
unsigned VecWidth = CI->getType()->getPrimitiveSizeInBits();
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (VecWidth == 128 && !IsSaturating)
IID = Intrinsic::x86_avx512_vpdpwssd_128;
else if (VecWidth == 256 && !IsSaturating)
@@ -4436,7 +4436,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpwssds_512;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4461,7 +4461,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
NewArgType = VectorType::get(Builder.getInt16Ty(), 32, false);
else
reportFatalUsageErrorWithCI(
- "Above intrinsic has unexpected vector bit width", CI);
+ "Intrinsic has unexpected vector bit width", CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4474,7 +4474,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
} else if (Name == "addcarryx.u32" || Name == "addcarryx.u64" ||
Name == "addcarry.u32" || Name == "addcarry.u64" ||
Name == "subborrow.u32" || Name == "subborrow.u64") {
- Intrinsic::ID IID = 0;
+ Intrinsic::ID IID;
if (Name[0] == 'a' && Name.back() == '2')
IID = Intrinsic::x86_addcarry_32;
else if (Name[0] == 'a' && Name.back() == '4')
@@ -4484,7 +4484,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[0] == 's' && Name.back() == '4')
IID = Intrinsic::x86_subborrow_64;
else
- reportFatalUsageErrorWithCI("Above intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
// Make a call with 3 operands.
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
@@ -4503,7 +4503,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
upgradeAVX512MaskToSelect(Name, Builder, *CI, Rep)) {
// Rep will be updated by the call in the condition.
} else
- reportFatalUsageErrorWithCI("Above intrinsic is invalid", CI);
+ reportFatalUsageErrorWithCI("Intrinsic is invalid", CI);
return Rep;
}
>From bcf96ea5d899282bf25efa196d3540548ccb38da Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 12:08:44 +0530
Subject: [PATCH 11/19] nitpick
---
llvm/lib/IR/AutoUpgrade.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 13c2d910198c4..54cbe3c7bb140 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -65,7 +65,8 @@ static void rename(GlobalValue *GV) { GV->setName(GV->getName() + ".old"); }
// Report a fatal error along with the
// Call Instruction which caused the error
-[[noreturn]] static void reportFatalUsageErrorWithCI(StringRef reason, CallBase *CI) {
+[[noreturn]] static void reportFatalUsageErrorWithCI(StringRef reason,
+ CallBase *CI) {
CI->dump();
reportFatalUsageError(reason);
}
@@ -4404,8 +4405,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt8Ty(), 64, false);
else
- reportFatalUsageErrorWithCI(
- "Intrinsic has unexpected vector bit width", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected vector bit width",
+ CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
@@ -4460,8 +4461,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512)
NewArgType = VectorType::get(Builder.getInt16Ty(), 32, false);
else
- reportFatalUsageErrorWithCI(
- "Intrinsic has unexpected vector bit width", CI);
+ reportFatalUsageErrorWithCI("Intrinsic has unexpected vector bit width",
+ CI);
Args[1] = Builder.CreateBitCast(Args[1], NewArgType);
Args[2] = Builder.CreateBitCast(Args[2], NewArgType);
>From 33e954fb0887704e35e3de2e89fb521ae15132c3 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 12:13:07 +0530
Subject: [PATCH 12/19] nitpick
---
llvm/lib/IR/AutoUpgrade.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 54cbe3c7bb140..36f283b180cba 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -66,7 +66,7 @@ static void rename(GlobalValue *GV) { GV->setName(GV->getName() + ".old"); }
// Report a fatal error along with the
// Call Instruction which caused the error
[[noreturn]] static void reportFatalUsageErrorWithCI(StringRef reason,
- CallBase *CI) {
+ CallBase *CI) {
CI->dump();
reportFatalUsageError(reason);
}
>From 3b06743fc6d11634392a34286ef48ac0202d4b44 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 31 Jan 2026 12:50:51 +0530
Subject: [PATCH 13/19] fix tests
---
llvm/test/Verifier/issue176674.ll | 2 +-
llvm/test/Verifier/issue176674_1.ll | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/Verifier/issue176674.ll b/llvm/test/Verifier/issue176674.ll
index 95267a7072426..e50ef80de8899 100644
--- a/llvm/test/Verifier/issue176674.ll
+++ b/llvm/test/Verifier/issue176674.ll
@@ -1,6 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
; CHECK: %v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
-; CHECK: LLVM ERROR: Above intrinsic is invalid
+; CHECK: LLVM ERROR: Intrinsic is invalid
define void @test(ptr %a) {
%v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
diff --git a/llvm/test/Verifier/issue176674_1.ll b/llvm/test/Verifier/issue176674_1.ll
index 0aff7090c5ae6..d5c92aa26bc39 100644
--- a/llvm/test/Verifier/issue176674_1.ll
+++ b/llvm/test/Verifier/issue176674_1.ll
@@ -1,6 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
; CHECK: %v = call <4 x i32> @llvm.x86.sse2.pshufl.w(<4 x i32> zeroinitializer, i8 0)
-; CHECK: LLVM ERROR: Above intrinsic has invalid signature
+; CHECK: LLVM ERROR: Intrinsic has invalid signature
define void @test(ptr %a) {
%v = call <4 x i32> @llvm.x86.sse2.pshufl.w(<4 x i32> zeroinitializer, i8 0)
>From f4a93a46bfe4a1ad70871df57cb20f9e3c8696e4 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Mon, 2 Feb 2026 23:50:01 +0530
Subject: [PATCH 14/19] nitpick
---
llvm/test/Verifier/issue176674.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/Verifier/issue176674.ll b/llvm/test/Verifier/issue176674.ll
index e50ef80de8899..c5221b1bb0cf3 100644
--- a/llvm/test/Verifier/issue176674.ll
+++ b/llvm/test/Verifier/issue176674.ll
@@ -1,6 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
; CHECK: %v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
-; CHECK: LLVM ERROR: Intrinsic is invalid
+; CHECK: LLVM ERROR: Unexpected intrinsic
define void @test(ptr %a) {
%v = call <4 x i32> @llvm.x86.sse2.pshuflw.128(<4 x i32> zeroinitializer, i8 0)
>From 2dd87f4a2d7afab7e4bc94207c79d0bd737ef08a Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Mon, 2 Feb 2026 23:55:25 +0530
Subject: [PATCH 15/19] nitpick
---
llvm/lib/Transforms/Utils/LoopUtils.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 9c2710a22a0db..e3cdc2487cc2a 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -30,6 +30,7 @@
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
+#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Instructions.h"
@@ -1895,10 +1896,11 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
// invalidating iterators.
if (isInstructionTriviallyDead(Inst, TLI))
DeadInsts.push_back(Inst);
-
+ ExitVal->dump();
// Replace PN with ExitVal if that is legal and does not break LCSSA.
if (PN->getNumIncomingValues() == 1 &&
LI->replacementPreservesLCSSAForm(PN, ExitVal)) {
+ llvm::errs() << "Hello";
PN->replaceAllUsesWith(ExitVal);
PN->eraseFromParent();
}
>From 0664871d6e58b6dfc4eb1967f3efe1697b0394ea Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Tue, 3 Feb 2026 00:02:09 +0530
Subject: [PATCH 16/19] nitpick
---
llvm/lib/Transforms/Utils/LoopUtils.cpp | 3 ---
llvm/test/Verifier/issue176674_1.ll | 2 +-
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index e3cdc2487cc2a..ab13374f69b20 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -30,7 +30,6 @@
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
-#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Instructions.h"
@@ -1896,11 +1895,9 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
// invalidating iterators.
if (isInstructionTriviallyDead(Inst, TLI))
DeadInsts.push_back(Inst);
- ExitVal->dump();
// Replace PN with ExitVal if that is legal and does not break LCSSA.
if (PN->getNumIncomingValues() == 1 &&
LI->replacementPreservesLCSSAForm(PN, ExitVal)) {
- llvm::errs() << "Hello";
PN->replaceAllUsesWith(ExitVal);
PN->eraseFromParent();
}
diff --git a/llvm/test/Verifier/issue176674_1.ll b/llvm/test/Verifier/issue176674_1.ll
index d5c92aa26bc39..0aff7090c5ae6 100644
--- a/llvm/test/Verifier/issue176674_1.ll
+++ b/llvm/test/Verifier/issue176674_1.ll
@@ -1,6 +1,6 @@
; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
; CHECK: %v = call <4 x i32> @llvm.x86.sse2.pshufl.w(<4 x i32> zeroinitializer, i8 0)
-; CHECK: LLVM ERROR: Intrinsic has invalid signature
+; CHECK: LLVM ERROR: Above intrinsic has invalid signature
define void @test(ptr %a) {
%v = call <4 x i32> @llvm.x86.sse2.pshufl.w(<4 x i32> zeroinitializer, i8 0)
>From b3528db0cd95e23b3d6ea90dd1d14bc38caf44d2 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Tue, 3 Feb 2026 00:03:20 +0530
Subject: [PATCH 17/19] nitpick
---
llvm/lib/Transforms/Utils/LoopUtils.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index ab13374f69b20..9c2710a22a0db 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -1895,6 +1895,7 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI,
// invalidating iterators.
if (isInstructionTriviallyDead(Inst, TLI))
DeadInsts.push_back(Inst);
+
// Replace PN with ExitVal if that is legal and does not break LCSSA.
if (PN->getNumIncomingValues() == 1 &&
LI->replacementPreservesLCSSAForm(PN, ExitVal)) {
>From 2738720a966e25bfea77fee5a3700efa6489dc2f Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Tue, 3 Feb 2026 00:13:50 +0530
Subject: [PATCH 18/19] upgrade intrinsic statement
---
llvm/lib/IR/AutoUpgrade.cpp | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 36f283b180cba..05cdbceb34b29 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -2625,7 +2625,7 @@ static bool upgradeAVX512MaskToSelect(StringRef Name, IRBuilder<> &Builder,
else if (Name[9] == 'q' && VecWidth == 512)
IID = Intrinsic::x86_avx512_conflict_q_512;
else
- llvm_unreachable("Unexpected intrinsic");
+ llvm_unreachable(" ");
} else if (Name.starts_with("pavg.")) {
if (Name[5] == 'b' && VecWidth == 128)
IID = Intrinsic::x86_sse2_pavg_b;
@@ -3030,7 +3030,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
Intrinsic::ID IID;
switch (VecWidth) {
default:
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
break;
case 128:
IID = Intrinsic::x86_avx512_vpshufbitqmb_128;
@@ -3064,7 +3064,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_fpclass_pd_512;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
Rep =
Builder.CreateIntrinsic(IID, {CI->getOperand(0), CI->getArgOperand(1)});
@@ -3088,7 +3088,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
Value *Mask = Constant::getAllOnesValue(CI->getType());
if (VecWidth == 512)
@@ -4244,7 +4244,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 256 && EltWidth == 64)
IID = Intrinsic::x86_fma_vfmaddsub_pd_256;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
Value *Ops[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4319,7 +4319,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && EltWidth == 64)
IID = Intrinsic::x86_avx512_pternlog_q_512;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2), CI->getArgOperand(3)};
@@ -4346,7 +4346,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && High)
IID = Intrinsic::x86_avx512_vpmadd52h_uq_512;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4381,7 +4381,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpbusds_512;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4437,7 +4437,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (VecWidth == 512 && IsSaturating)
IID = Intrinsic::x86_avx512_vpdpwssds_512;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2)};
@@ -4485,7 +4485,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
else if (Name[0] == 's' && Name.back() == '4')
IID = Intrinsic::x86_subborrow_64;
else
- reportFatalUsageErrorWithCI("Intrinsic is unexpected", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
// Make a call with 3 operands.
Value *Args[] = {CI->getArgOperand(0), CI->getArgOperand(1),
@@ -4504,7 +4504,7 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
upgradeAVX512MaskToSelect(Name, Builder, *CI, Rep)) {
// Rep will be updated by the call in the condition.
} else
- reportFatalUsageErrorWithCI("Intrinsic is invalid", CI);
+ reportFatalUsageErrorWithCI("Unexpected intrinsic", CI);
return Rep;
}
>From 230d2f8aadf96440917e1427aa3b214c8c60043f Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Tue, 3 Feb 2026 00:16:49 +0530
Subject: [PATCH 19/19] nitpick
---
llvm/lib/IR/AutoUpgrade.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 05cdbceb34b29..dd22042f5cd39 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -2625,7 +2625,7 @@ static bool upgradeAVX512MaskToSelect(StringRef Name, IRBuilder<> &Builder,
else if (Name[9] == 'q' && VecWidth == 512)
IID = Intrinsic::x86_avx512_conflict_q_512;
else
- llvm_unreachable(" ");
+ llvm_unreachable("Unexpected intrinsic");
} else if (Name.starts_with("pavg.")) {
if (Name[5] == 'b' && VecWidth == 128)
IID = Intrinsic::x86_sse2_pavg_b;
More information about the llvm-commits
mailing list