[instcombine] delete the instruction in common branch when the condition is undef

I have a test case showed that the common branch cond.end will be unreasonably executed whenever the i1 undef is true or false, so does it make sense to delete store instruction base on the newest upstream branch ?

define dso_local i16 @e1() {
  br i1 undef, label %cond.true, label %cond.false
cond.true:                        ; preds = %entry
  store i16 1, i16* @c, align 2
  br label %cond.end
cond.false:                       ; preds = %entry
  store i16 0, i16* @c, align 2
  br label %cond.end
cond.end:                         ; preds = %cond.true, %cond.false
  store i32 13, i32* @b, align 4
  ret i16 0

Branch on undef is immediate undefined behavior, so all the following code is unreachable and removed.

1 Like