As discussed by Andrea on PR30486, we have an unsafe cast to an Instruction type in the select combine which doesn't take into account that it could be a ConstantExpr instead.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
Hi Simon,
the patch looks good to me.
I suggest to improve the test case by adding multiple cases to the switch statement. That would prove that the optimization still works okay even with constant expressions (see below).
Example:
@g = global i32 0
define i32 @func() {
switch i32 add (i32 ptrtoint (i32* @g to i32), i32 -1), label %x [
i32 1, label %one
i32 2, label %two
]
x:
ret i32 0
one:
ret i32 1
two:
ret i32 2
}The above case should be combined to this:
define i32 @func() {
switch i32 ptrtoint (i32* @g to i32), label %x [
i32 2, label %one
i32 3, label %two
]
x: ; preds = %0
ret i32 0
one: ; preds = %0
ret i32 1
two: ; preds = %0
ret i32 2Thanks!
Andrea
Comment Actions
Fixed in rL284000 - I added Andrea's alternate test case so we test both single case and multiple case switches.