[PATCH] D102367: [LowerConstantIntrinsics] only accept ConstantData other than UndefValue as constant

Nick Desaulniers via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 12 16:04:17 PDT 2021


nickdesaulniers added a comment.

In D102367#2755619 <https://reviews.llvm.org/D102367#2755619>, @nickdesaulniers wrote:

> In D102367#2755587 <https://reviews.llvm.org/D102367#2755587>, @nikic wrote:
>
>> Can you explain why UndefValue needs to be excluded? It's not mentioned in the summary, and the test case does not cover it.
>
> Looks like we disagree with GCC on:
>
>   int foo(void) {
>       int i;
>       return __builtin_constant_p(i);
>   }
>
> Oh, that doesn't produce `undef`...hmm.  @rsmith suggested it in https://bugs.llvm.org/show_bug.cgi?id=41459#c5. I'm happy to add a test for it, but I'm not sure precisely why @rsmith made that recommendation.

Seems like it's early-cse that messes that up:

  declare i1 @llvm.is.constant.i32(i32 %a) nounwind readnone
  define dso_local i32 @foo() #0 {
  entry:
    %0 = call i1 @llvm.is.constant.i32(i32 undef)
    %1 = zext i1 %0 to i32
    ret i32 %1
  }

`opt -passes=early-cse y.ll -S`

  ; ModuleID = 'y.ll'
  source_filename = "y.ll"
  
  ; Function Attrs: convergent nofree nosync nounwind readnone willreturn
  declare i1 @llvm.is.constant.i32(i32) #0
  
  define dso_local i32 @foo() {
  entry:
    ret i32 1
  }
  
  attributes #0 = { convergent nofree nosync nounwind readnone willreturn }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102367



More information about the llvm-commits mailing list