Issue 178874
Summary [IROutliner] Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed
Labels new issue
Assignees
Reporter svs-quic
    https://godbolt.org/z/rE63of7G8

The IR Outliner when run on 

```
define ptr @outliner_crash(ptr %arrayidx9.i) {
entry:
  br label %do.body.i

do.body.i: ; preds = %entry
  switch i8 0, label %do.end213.i [
    i8 5, label %do.end213.i
    i8 4, label %if.then202.i
  ]

if.then202.i: ; preds = %do.body.i
  %0 = load i8, ptr null, align 1
  %cmp11.not.i288 = icmp eq i8 1, 0
  %arrayidx14.i290 = getelementptr [2 x [3 x i8]], ptr getelementptr inbounds nuw (i8, ptr null, i32 4), i32 0
  ret ptr %arrayidx14.i290

do.end213.i: ; preds = %do.body.i, %do.body.i
  %1 = load i8, ptr %arrayidx9.i, align 1
  %cmp11.not.i = icmp eq i8 1, 0
  %arrayidx14.i265 = getelementptr [2 x [3 x i8]], ptr getelementptr inbounds nuw (i8, ptr null, i32 4), i32 0
  ret ptr null
}
```

as  `opt -S -passes=verify,iroutliner -ir-outlining-no-cost --debug-_only_=iroutliner`

crashes with the following assertion:

`opt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From*) [with To = llvm::Constant; From = llvm::Value]: Assertion isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.`

Looking at the outliner logs it looks like it is trying to replace the `ptr null` value in the `getelementptr` with a function argument `ptr %0` :

```
Replacing uses of constant ptr null in function

 ; Function Attrs: minsize optsize
define internal void @outlined_ir_func_0(ptr %0, ptr %1, i32 %2) #1 {
newFuncRoot:
  br label %if.then202.i_to_outline

if.then202.i_to_outline: ; preds = %newFuncRoot
  %3 = load i8, ptr null, align 1
  %cmp11.not.i288 = icmp eq i8 1, 0
  %arrayidx14.i290 = getelementptr [2 x [3 x i8]], ptr getelementptr inbounds nuw (i8, ptr null, i32 4), i32 0
  br label %if.then202.i_after_outline.exitStub

if.then202.i_after_outline.exitStub: ; preds = %if.then202.i_to_outline
  ret void

output_block_0_0:                                 ; No predecessors!
  store ptr %arrayidx14.i290, ptr %1, align 8
}

 with ptr %0
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to