[PATCH] D129650: [InstCombine] change conditions for transform of sub to xor

Zaara Syeda via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 09:36:14 PDT 2022


syzaara added a comment.

This change is causing issues with creating a SCEV expression for the subtract. This leads to not being able to delinearizing some expressions which can have an impact on loop passes like loop interchange. For example, with the attached{F23852262 <https://reviews.llvm.org/F23852262>} IR, we are no longer able to compute a simple SCEV expression for the subtract which is now an xor:
Output from -passes=print<scalar-evolution>

With the subtract:

    %_val_lda_ = load i32, i32* %.lda, align 4
    -->  %_val_lda_ U: full-set S: full-set
    %_conv = sext i32 %_val_lda_ to i64 
    -->  (sext i32 %_val_lda_ to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
    %_mult_tmp = shl nsw i64 %_conv, 3
    -->  (8 * (sext i32 %_val_lda_ to i64))<nsw> U: [0,-7) S: [-17179869184,17179869177)
    %_sub_tmp4 = sub nuw nsw i64 -8, %_mult_tmp
    -->  (-8 + (-8 * (sext i32 %_val_lda_ to i64))<nsw>)<nsw> U: [0,-7) S: [-17179869184,17179869177)
  %a_ix_dim_0_ = getelementptr i8, i8* %a_rvo_based_addr_, i64 %_ix_x_len11
  -->  {(-8 + %.a),+,(8 * (sext i32 %_val_lda_ to i64))<nsw>}<%_loop_2_do_>



With the xor:

    %_val_lda_ = load i32, i32* %.lda, align 4
    -->  %_val_lda_ U: full-set S: full-set
    %_conv = sext i32 %_val_lda_ to i64 
    -->  (sext i32 %_val_lda_ to i64) U: [-2147483648,2147483648) S: [-2147483648,2147483648)
    %_mult_tmp = shl nsw i64 %_conv, 3
    -->  (8 * (sext i32 %_val_lda_ to i64))<nsw> U: [0,-7) S: [-17179869184,17179869177)
    %_sub_tmp4 = xor i64 %_mult_tmp, -8
    -->  %_sub_tmp4 U: [0,-7) S: [-17179869184,17179869184)
  %a_ix_dim_0_ = getelementptr i8, i8* %a_rvo_based_addr_, i64 %_ix_x_len11 
  -->  {((8 * (sext i32 %_val_lda_ to i64))<nsw> + %_sub_tmp4 + %.a),+,(8 * (sext i32 %_val_lda_ to i64))<nsw>}<%_loop_2_do_>

Note that we do not recognize the xor as a subtract of 8 SCEV expression. This prevents further simplifications on expressions using _sub_tmp4, because it is now represented as a symbol rather than a recognized SCEV operation.
Would it be possible to revert this until we teach SCEV how to handle the XOR?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129650/new/

https://reviews.llvm.org/D129650



More information about the llvm-commits mailing list