This patch extends foldCmpLoadFromIndexedGlobal to fold IR below:
define i1 @cmp_load_constant_array0(i64 %x){ entry: %cond = icmp ult i64 %x, 2 br i1 %cond, label %case1, label %case2 case2: ret i1 0 case1: %isOK_ptr = getelementptr inbounds i32, ptr @CG, i64 %x %isOK = load i32, ptr %isOK_ptr %cond_inferred = icmp ult i32 %isOK, 3 ret i1 %cond_inferred }
Problem still:
Not globally optimized best.
Here I think if D152838 is accepted, that would be better.
Proof:
alive2
Related issue:
issue