This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFolding] Fix crash when folding vector llvm.is.fpclass
ClosedPublic

Authored by foad on Apr 20 2023, 7:05 AM.

Diff Detail

Event Timeline

foad created this revision.Apr 20 2023, 7:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 7:05 AM
foad requested review of this revision.Apr 20 2023, 7:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 7:05 AM
This revision is now accepted and ready to land.Apr 20 2023, 7:30 AM
This revision was landed with ongoing or failed builds.Apr 20 2023, 7:35 AM
This revision was automatically updated to reflect the committed changes.

I've bisected a failed assert to this commit. Repro:

$ cat repro.c 
int a;
float *b;
float c;
void d() {
  float *e = d;
  for (int f = 0; f < a; f++) {
    c = b[f];
    e[f] = 10.f * c;
    if (__builtin_isnormal(e[f]))
      e[f] = 351.f;
  }
}
$ clang -target aarch64-linux-gnu -c repro.c -O2
clang: ../lib/IR/Instructions.cpp:652: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.
foad added a comment.EditedApr 21 2023, 1:26 AM

I've bisected a failed assert to this commit. Repro:

$ cat repro.c 
int a;
float *b;
float c;
void d() {
  float *e = d;
  for (int f = 0; f < a; f++) {
    c = b[f];
    e[f] = 10.f * c;
    if (__builtin_isnormal(e[f]))
      e[f] = 351.f;
  }
}
$ clang -target aarch64-linux-gnu -c repro.c -O2
clang: ../lib/IR/Instructions.cpp:652: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.

Thanks! Here's an IR repro:

; RUN: opt < %s -passes=loop-vectorize -S | FileCheck %s

target triple = "aarch64-unknown-linux-gnu"

define void @d() {
bb:
  br label %bb2

bb1:
  ret void

bb2:
  %i = phi i64 [ 0, %bb ], [ %i7, %bb2 ]
  %i3 = load float, ptr null, align 4
  %i4 = getelementptr float, ptr @d, i64 %i
  %i5 = tail call i1 @llvm.is.fpclass.f32(float 0.0, i32 0)
  %i6 = select i1 %i5, float 0.0, float 0.0
  store float %i6, ptr %i4, align 4
  %i7 = add i64 %i, 1
  %i8 = icmp eq i64 %i7, 0
  br i1 %i8, label %bb1, label %bb2
}

declare i1 @llvm.is.fpclass.f32(float, i32 immarg)

The problem is that VPWidenCallRecipe::execute assumes that vector intrinsics are overloaded on their result type. llvm.is.fpclass is overloaded on the type of its first argument instead. I'm not sure what the best fix is. @fhahn?

foad added a subscriber: fhahn.Apr 21 2023, 1:27 AM
foad added a comment.Apr 21 2023, 1:55 AM

Suggested fix: D148905

hokein added a subscriber: hokein.Apr 21 2023, 3:53 AM

Thanks for the quick fix, @foad. I encountered some internal failures caused by this patch as well. While the fix is waiting for review, can we temporarily revert this patch until the fix is ready?

foad added a comment.Apr 21 2023, 6:18 AM

Thanks for the quick fix, @foad. I encountered some internal failures caused by this patch as well. While the fix is waiting for review, can we temporarily revert this patch until the fix is ready?

Done. I'll fold this patch into D148905.

Thanks for the quick fix, @foad. I encountered some internal failures caused by this patch as well. While the fix is waiting for review, can we temporarily revert this patch until the fix is ready?

Done. I'll fold this patch into D148905.

Thanks!